Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter drewnorman

    (@drewnorman)

    Hi @maybellyne,

    No problem. I understand our setup is a bit complicated.

    For anyone else running into this issue, I was able to load the correct meta descriptions for the various CPTs with the following:

    function adjust_yoast_meta_descriptions($description, $presentation) {
    $meta = YoastSEO()->meta->for_post(get_the_ID());
    return !empty($meta) ? $meta->description : '';
    }
    add_filter('wpseo_metadesc', 'adjust_yoast_meta_descriptions', 10, 2);

    Because by default Yoast uses the current URL to determine the appropriate meta description and any custom routing can prevent proper post identification from the URL alone, the filter above explicitly requests the meta description from Yoast for the current post ID and updates the existing meta description accordingly.

    Thread Starter drewnorman

    (@drewnorman)

    Hello @611shabnam ,

    Thank you for getting back to me so promptly.

    Yes, you have followed the correct steps as I had initially described and it appears to be working for you. However, I’m just now noticing the error only occurs for CPTs that have had their link adjusted via the post_type_link hook, which I think is a pretty strong lead. We currently have a handful of CPTs that use flat URLs (e.g. ‘{domain}/{cpt-slug}’) and we’re utilizing custom routing to infer the post type from the slug, load the correct CPT post, and pass it to the corresponding template.

    So I’m guessing Yoast tries to automatically determine the CPT post for a route and loads its meta description, but because we’re using custom routing, this breaks down. Assuming I’m on the right track as to the source of the issue, the question is how to adjust how Yoast loads a CPT post for a route to support our custom routes.

    I understand this is a much more specific scenario than originally described, but I’m open to any ideas considering how frequently we set up custom routing.

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