• Resolved mayukhnair

    (@mayukhnair)


    I have a WordPress site with Yoast SEO installed on it. I have a certain page, /charts, which accepts the GET parameter id. Based on the value of ID, I want to load a title and description from a text file on the server, and set it as the title and description that shows up on a snippet when you paste the link on Twitter, Facebook, Slack, etc.

    Yoast overrides that with its logic, and I could not figure out if a custom variable in Yoast could be set up that sets the title and description from the file based on id‘s value. I ended up trying this solution to bypass Yoast for that particular page but as a result, no snippet shows up at all when I paste the link.

    Note that apart from this /charts page, I do not want to alter Yoast’s behaviour anywhere on the site. Is a solution possible to the same that changes the title and meta description dynamically with the id value in the GET parameter?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello @mayukhnair

    Thanks for using the Yoast SEO plugin. As much as we hate to say it, your question goes beyond the technical expertise of the Yoast support team. Therefore, we can’t give you a solid answer to your question.

    But we don’t want to leave you empty-handed. Our developer portal at developer.yoast.com has proven helpful to many developers in the past and hopefully will serve you well too.

    Sorry, we can’t be of more help here.

    Thread Starter mayukhnair

    (@mayukhnair)

    Thanks for the response. Luckily I was able to solve the problem, so I’m leaving the answer here for the rest who may stumble upon this.

    You still need to add the action remove_wpseo to functions.php to override Yoast on the page.

    add_action( 'template_redirect', 'remove_wpseo' ); 
    /** * Removes output from Yoast SEO on the frontend for a specific post, page or custom post type. */ 
    function remove_wpseo() { 
    if ( is_single ( 1 ) ) { 
    $front_end = YoastSEO()->classes->get( Yoast\WP\SEO\Integrations\Front_End_Integration::class ); 
    remove_action( 'wpseo_head', [ $front_end, 'present_head' ], -9999 ); 
    } 
    }

    Turns out link previews on apps are dictated by the Open Graph meta tags, which is what I was missing. I added <meta property = 'og:title' content = '<dynamic title content based on the ID>' /> to my page code, and it worked. Without the 'og:title' property defined for your page title, link previews may not work for an app.

    You can use the existing <meta name='description' property to add a description dynamically.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Override Yoast SEO snippet with custom text/description’ is closed to new replies.