How to change the "title" in WP-JSON response, but only for a specific post

Is there a way in WP site to change / filter the "title" in wp-json associated with the title? For example, if the wp-json page has:

"title": "Listing details"

Can this be changed to:

"title": "Some Other Title"

The reason for this is that the purchased software generates pages from the database using one post as a template, presumably through some sort of htaccess rules. These pages are created on one WP page. Other attributes are manipulated, but not this. Thus, if the page title in WP Admin is "Details", but the page title and the H1 in HTML, through this acquired software, are instead the characteristics of the Rotten Egg, "the title and H1 will be filled with" Egg rot specifics "but the title attribute in json will still say "Details".

I would have thought there is a way to filter this inside functions.php, but I cannot find the relevant documentation. The other one I actually tried is my backup plan, is the code that disables it for a specific entry like this:

function elim_json($content)
{
if ( is_single( '17' ) {
$content = str_replace('rel="alternate" type="text/xml+oembed"', 'rel="" 
type=""',$content);
return $content;
}
}
add_filter('wp_headers','elim_json');

      

Again, disabling the link from the post is not preferred. I would rather change what is displayed on the header linked page via HTML like below:

<link rel="alternate" type="application/json+oembed" href="https://www.someurl.com/wp-json/oembed/1.0/embed?url=encoded_url_here" /> 

      

I think the answer lies in the codex re actions and filters for the rest of the api: http://v2.wp-api.org/extending/hooks/

Here I tried to add the following to my functions.php file:

add_action( 'rest_api_init', 'change_wp_json_url' );
function change_wp_json_url() {
    register_rest_field( 'post',
        'starship',
        array(
            'get_callback'    => 'slug_get_starship',
            'update_callback' => 'slug_update_starship',
            'schema'          => null,
        )
    );
}

      

I'm not sure if this is remotely close to correct.

0


source to share





All Articles