Is it possible to enqueue the Youtube API script or does it have to be inline?

First, make sure the YT api is enqueued() and added to the footer. function wp_enqueue_scripts__youtube_api() { wp_enqueue_script( ‘yt-player-api’, ‘http://www.youtube.com/player_api’, array(), false, true ); } add_action( ‘wp_enqueue_scripts’, ‘wp_enqueue_scripts__youtube_api’ ); Next, output your div somewhere on the page. <div id=”‘ . $postid . ‘player”></div> Then, hook into wp_footer and make sure you set the priority higher that … Read more

Retrieving pages with multiple tags using REST API

I ran into the same problem but for posts. I found how to OR or AND tags together here: https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters To get entries that have both L1 AND L2 AND L3 ; use plus (+) https://example.com/cms/wp-json/pages?filter[tag]=L1+L2+L3 In case somebody else comes along and wants to OR terms together I’ll save you the trouble: To get … Read more

How to build an API as a plugin

First thing is the add rewrite rule function. You have – add_rewrite_rule(‘^wp-api/pugs/?([0-9]+)?/?’,’index.php?__wp-api=1&pugs=$matches[1]’,’top’); wp-api/pugs/?([0-9]+) this means, when you request <url>/wp-api/pugs/123, you will get a query variable pugs with parameter 123. $var = get_query_var(‘pugs’); // = 123 Now, you don’t really need pugs in the url as per you needs. So, just remove it this way. Also, … Read more

WordPress Rest API

What version of the REST API are you using? If you’re using the version that’s bundled with WordPress 4.4 (ie, v2), you’ll need to change your url to something like http://example.com/wp-json/wp/v2/posts. Reference WP API version 2 docs

Change Page’s Tag Using functions.php File

Check this out function custom_title($title_parts) { $title_parts[‘title’] = “Page Title”; return $title_parts; } add_filter( ‘document_title_parts’, ‘custom_title’ ); In custom_title, $title_parts contains ‘title’, ‘page’ (the pagination), ‘tagline’ (the slogan you specified) and ‘site’. Set “title” the way you like.

How to use WP_Error $data argument?

$this->error_data[$code] … the WP_Error object holds $data in an array and $code is the key. The add_data method clearly states: The error code can only contain one error data. But the $data (mixed) can be an array or an object and carry as many keys/properties as you need. It’s up to your handlers how they … Read more

Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?

Yes, you open your site to being requested via AJAX to any other script in the whole web. It would be better if you limit the origin to one specific remote domain from which you are consuming the API, like this example: header(“Access-Control-Allow-Origin: http://mozilla.com”); However as the mozilla documentation states, a client can fork the … Read more

WordPress JSON output

If you are using PHP 5.2+ you’re best bet is to just make a PHP array or object and use json_encode(). UPDATED: $cats = get_categories(); $output = array(‘categories’ => array()); foreach ($cats as $cat) { $cat_output = array( ‘cat_id’ => $cat->term_id, ‘cat_name’ => $cat->name, ‘posts’ => array(), ); // should be able to use -1 … Read more

Disable requests to api.wordpress.org

You can Disable HTTP Calls by adding this in your wp-config.php define( ‘WP_HTTP_BLOCK_EXTERNAL’, TRUE ); This will disable/block all external HTTP requests and will make website alot faster. And then you can whitelist domains that you don’t want to block. define( ‘WP_ACCESSIBLE_HOSTS’, ‘example.com, domain.com’ );

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