Adding rest api endpoints to an old theme

WordPress REST API has nothing directly to do with the theme, REST API is in the WordPress core, and any plugin and theme can be made to support it. Normal WordPress themes don’t use REST API: it is relatively new part of the WordPress, and so far, very few themes are made to use REST … Read more

How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?

If you know the existing callback and priority you can just remove the filters and then add again at a different priority: remove_filter( ‘the_content’, ‘convert_smilies’, 20 ); add_filter( ‘the_content’, ‘convert_smilies’, 30 ); remove_filter( ‘the_content’, ‘capital_P_dangit’, 11 ); add_filter( ‘the_content’, ‘capital_P_dangit’, 20 );

Implementing an AJAX POST API call in wordpress

You got the error 400 Bad Request because the Content-Type header is application/json: $.ajax({ headers:{ “Content-Type”:”application/json” }, data: { … }, … }); And when the request content is a JSON string, the $_REQUEST[‘action’] which WordPress uses to identify the proper AJAX action (which is foo in your code) is not available (i.e. it’s a … Read more

How to add WP API and JS featured image attachment

I manage to solved it by adding this code (at the bottom) to the YOUR BLOG THEMES my path : wp-content/themes/twentysixteen/function.php: function ws_register_images_field() { register_rest_field( ‘post’, ‘images’, array( ‘get_callback’ => ‘ws_get_images_urls’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘ws_register_images_field’ ); function ws_get_images_urls( $object, $field_name, $request ) { $medium = wp_get_attachment_image_src( get_post_thumbnail_id( … Read more

Passing a borrowed nonce through Postman fails

For remote apps (cURL, Postman, etc.), or when not using the browser, you should use an authentication plugin like Application Passwords instead of sending the cookies. But if you’d rather send the cookies, then copy and send the WordPress logged-in cookie named wordpress_logged_in_<hash>. Example in cURL: curl -H “X-WP-Nonce: <nonce>” -X POST https://example.com/wp-json/wp/v2/posts -d “Data … Read more