0

I'm curious if there's a supported method for providing the <meta og:description="%VALUE%"> tag to my page for a custom template.

So far I've added an action to wpseo_head to echo out a meta description tag that doesn't leverage open graph. But, I see that the aforementioned is by default getting that description information from the_content().

Normally this would be fine, but for the specific page(s) that will be using this template, the data will be provided from an outside GUI (where this data is also warehoused) from which this template will query from, pass specific pieces of data/content through to the proper wpautop()/do_shortcode()/etc. functions, and finally render the output. So, "the content" field won't be used at all in this scenario.

One of the specific pieces of data is what I'd like Yoast SEO to use for building the meta og description tag.

I'm aware that I don't need Yoast SEO to accomplish what I'm looking for, overall. However, since this plugin is already heavily relied upon from legacy content, I want to try to proxy as much of this type of meta content through it; if possible.

I'm still traversing the source. If I find a solution before someone else suggests one, I'll add my findings.

EDIT

I've also discovered wpseo_opengraph and tried removing the filter for description and adding in my own, but it seems like it looks to be more heavily embedded at first glance. Doing that didn't change the specific meta tag I'm trying to set manually.

1 Answer 1

1

Way overthinking it:

<?php

add_filter('wpseo_opengraph_desc', function () use (&$data) {
    $seo_intro = trim($data->seo_intro);

    if ($seo_intro === '') {
        $seo_intro = "{$data->name} - {$data->title}";
    }

    return esc_attr(wp_strip_all_tags(stripslashes(do_shortcode($seo_intro))));
}, PHP_INT_MAX);

?>

Essentially, hijack the content with a filter (since that's what Yoast is using to derive the description) and make sure it's the last filter to be ran to return back my predetermined content.

EDIT

Instead of adding a filter on the_content, use Yoast's custom filter wpseo_opengraph_desc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.