AMP version of front page without plugin

is_single() will return false for Pages, so the above code as written should only work for single Posts. You’ll need to add more conditionals to your amp_page_template() function for each of the templates you want to replace with an AMP version. Depending on your settings in Settings > Reading > Front page displays, is_front_page() might … Read more

How to add an endpoint for my custom post type? /wp-json/wp/v2/posts is working but it didn’t in the custom post

The “register_rest_field” function will add and handle data update for a given endpoint, looks like it’s not what you are looking for. The register_post_type() function accepts a “show_in_rest” and “rest_base” params if you want to use a custom slug for the endpoint: https://codex.wordpress.org/Function_Reference/register_post_type By default it uses the WP_REST_Posts_Controller class to handle the methods (get, … Read more

How to fix AWS SNS API end point code that cause site not to load?

The root cause is this: function sns_endpoint_data() { // this line caused the site not to load $message = Message::fromRawPostData(); /* additional code follows… */ } add_action( ‘template_redirect’, ‘sns_endpoint_data’ ); There is no if condition checking if this is indeed the URL you desired to do this on. As a result, the Message::fromRawPostData() will load … Read more

REST Endpoint API 404

There are few problems: you are using \WP_REST_Server::CREATABLE which is executed only when the request type is POST, if you are just opening the URL in the browser use \WP_REST_Server::READABLE instead (or \WP_REST_Server::ALLMETHODS to accept any request type). your callback is ‘callback’ => [$this, ‘import_csv’], but it should be ‘callback’ => [$this, ‘import_csv_file’], as the … Read more

How to call code when adding WooCommerce menu items via woocommerce_account_menu_items

One needs to create an action hook ‘woocommerce_account_[myendpoint]_endpoint’: add_action(‘woocommerce_account_’ . $endpoint . ‘_endpoint’, ‘my_endpoint_content’); function my_endpoint_content() { //content goes here echo ‘My content goes here’; } http://hookr.io/actions/woocommerce_account_key_endpoint/ So, putting a few different sources together, to add a new menu item to the Woocommerce My Account dashboard one needs something like: <?php add_filter(‘woocommerce_account_menu_items’, ‘add_my_menu_items’); function add_my_menu_items($items) … Read more

Custom route and query

There are 3 issues with your code: The proper syntax of registering your custom REST API route, is as follows: register_rest_route( $namespace, $base_URL, $args, $override ); So: register_rest_route( ‘boss/v1’, ‘/latest-quiz-results’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_latest_quiz_results’ ) ); Consult the reference for more information. In the get_latest_quiz_results(), $wpdb is not defined because you’re missing … Read more

WooCommerce Endpoints content

Dang it…must be blind….FOUND IT. The solution is, that since this is a custom hook, and most likely using JQuery, you place the end point action within the call. Instead of this: function mylistings_information_endpoint_content() { echo ‘THIS IS A TEST OF THE CONTENT’; } add_action( ‘woocommerce_account_information_endpoint’, ‘mylistings_information_endpoint_content’ ); It is this: function **mylistings**_information_endpoint_content() { echo … Read more

Implementing a URL Shortener

Step 1: Create a new template file in your themes folder named: shorturl.php <?php /* Template Name: Short URLS Template Post Type: post, page */ while ( have_posts() ) : the_post(); $content=get_the_content(); header(‘Location: ‘.str_replace(“&amp;”,”&”,$content)); exit(); endwhile; Step 2: Create a new php file in your wp-content/plugins/ folder and name it: public-url-shortener.php <?php /* Plugin Name: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)