• Resolved geochanto

    (@geochanto)


    I’m using a headless WordPress with WP-API.

    So, I’m exposing yoast data in the API. With something like this:

    'yoast_wpseo_title' => wpseo_replace_vars(get_post_meta($post->ID, '_yoast_wpseo_title', true), $post)

    I have default SEO titles with snippet variables set for each of my post types under search apperance -> content types.

    Weird thing is that if the seo title for the post is modified, it seems to save and this function returns me the correct title.

    But if the default title is untouched, then the above function returns null. Moreover, if I edit the title back to the default, it also returns null.

    I’m not running into this with regular WordPress sites when using standard PHP functions to directly render these fields.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    We can’t offer support on custom code (needed to change (core) features of our plugin). Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thread Starter geochanto

    (@geochanto)

    Can you point to any documentation on how snippet variables are handled by Yoast? Like where the variables are stored in the DB etc?

    Hi,

    The default ones are stored in wp_options where option_name iswpseo_titles`. This is where the template variables are stored.

    Plugin Support Jerlyn

    (@jerparx)

    Closed. No further questions.

    Thread Starter geochanto

    (@geochanto)

    Hi there. I know it’s been a while but I found why this issue occurs.

    It looks like when no changes are made in the Yoast SEO title, and left with just default snippet variables, the _yoast_wpseo_title field doesn’t get added to the wp_postmeta table. When the title is modified, it gets added. If the title is reverted back to default, it again gets removed.

    Unless there’s a specific reason it works this way, I would think it’s a bug.

    I have also noticed this, I reckon it is almost definitely a bug.

    get_post_meta( $id, '_yoast_wpseo_title', true );

    always returns blank if it only contains snippet variables (which is the default for all fields). The only way to get this to return a value is to remove the snippet variables and add some custom text. This makes using Yoast for Headless CMS (which is fast becoming a popular choice for people) almost impossible.

    Unless of course I am missing something?

    Just to add to this, there’s definitely something really odd going on. If I update the default meta desc (in the Content Types tab in the yoast admin screen) and then enter this exact same meta desc for a specific page, the output is blank.

    e.g. If my meta desc was ‘Example meta desc.’ as my default for posts and I try to enter that exact same meta desc for a specific post, the meta will show as blank. If I remove the full stop so it now says ‘Example meta desc’, the meta will show with that text. It seems that defaults just don’t work at the moment for get_post_meta() ??

    Not sure why this ticket is down as resolved?

    Plugin Support marcanor

    (@marcanor)

    Hi @quirksmode , @geochanto

    Based on the information you provided, we expect this to be a bug. We’re actively using the bug tracking on our GitHub repository so your best next step would be to create a new issue for our developers at https://github.com/Yoast/wordpress-seo/issues/new. You will need an account to create a new issue. If this is your first bug report, please check out: https://kb.yoast.com/kb/how-to-write-a-good-bug-report/.

    Don’t forget to include the URL to this conversation in your bug report.

    Thread Starter geochanto

    (@geochanto)

    Hey @quirksmode I found a workaround for this. Apparently you can call get_option('wpseo_titles'), which returns all default titles for your post and taxonomy types.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Default Site titles with snippet variables not saving when post is published’ is closed to new replies.