How to Setup SEO Title using WordPress Rest API

#579199
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    We save all our metadata on post meta field. Please note that we don’t have any routes in the REST API from WordPress to update these fields so you would need to update them like you would for any other default postmeta entry. The meta fields are the following: rank_math_title or rank_math_description

    So, you can create your own custom REST API functions to update Rank Math fields in the post meta table. You can refer to the following article as an introduction: https://mklasen.com/updating-custom-post-meta-via-the-wordpress-rest-api/

    Hope that helps.

    Thank you.

    Hi, I follow add rank_math_title but nothing happens the title SEO is still %title%. Here is my code.

    URL = f’https://{wordpress_domain}/wp-json/wp/v2/posts’
    DATA = {
    ‘title’ : tile,
    ‘rank_math_title’ : title seo,
    ‘content’: content
    }
    wp_response = requests.post(url=URL, headers=HEADERS, json=DATA)

    Can you help me? Thanks

    Hello,

    That’s not the correct implementation to save data into the postmeta table using the WordPress REST API. For that, you need the data to have the meta key information like so:

    
    data = {
        'meta': {
            'rank_math_title': 'My Title',
            'rank_math_description': 'My Description'
        }
    }
    

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    I changed the code but nothing happen. Title SEO is still %title%, not Title SEO. Do I need to enable anything?

    The code:

    URL = f'https://{wordpress_domain}/wp-json/wp/v2/posts'
    DATA = {
        'title' : title,
        'meta': {
            'rank_math_title': 'Title SEO',
            'rank_math_description': 'My Description'
        },
        'content': content,
        'slug': slug,
        'status' : 'draft',
        'categories': '1',
        'featured_media': thumbnail,
        'author': '2'
        }
    wp_response = requests.post(url=URL, headers=HEADERS, json=DATA)

    Pls check my code. I need further assistance as the problem still exist

    Hello,

    Can you please confirm if you have applied the correct authorization header (bearer token) for this specific API request?

    Please share the final code you made including the headers. This is so we can understand further how you have implemented the REST API code.

    You can share the code using this tool https://pastebin.com/ and share the URL in the Sensitive Data section of this thread.

    Looking forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    That creates the metadata correctly but you need a function to run through all those and add them to the postmeta table correctly.

    One example of such a function would be this one: https://stackoverflow.com/questions/42384841/wp-rest-api-create-posts-with-custom-fields-generated-by-cpt/53237658#53237658

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)

The ticket ‘How to Setup SEO Title using WordPress Rest API’ is closed to new replies.