Get Yoast meta outside of the loop?
-
How do I get the Yoast meta data to be retrieved outside of the WP loop?
I need to fetch certain Yoast metas to be echoed to the header, because Facebook and others needs that info, for example, and Yoast does not (yet) output these specific meta tags.
I have been able to get the data processed in/after the content with this code, where the second line processes the %% variables:
$yoast_title = get_post_meta( get_the_ID(), '_yoast_wpseo_title', true ); $yoast_title_dc = apply_filters( 'wpseo_title', wpseo_replace_vars( $yoast_title ) );
This works great if I echo the output to the footer, but not in the wp_head. ?? It just echoes an empty field value.
I need this for the following:
I have several event pages (city tours) on my blogs. Each (same) tour is organized 5 times a week, so Google needs a (custom) canonical url of course. The standard Yoast output does this and Google loves it.But on Facebook it goes wrong. ??
When I scrape (https://developers.facebook.com/tools/debug/) an event page, it will only display the info of the canonical url and not the actual event. This makes sharing it to Facebook really impossible…I tested several things and if I add certain fb: tags, provided by Facebook, it does work while Google just ignores them. But for that I need to put them within the <head> tag.
Let’s say the actual event (page) is called “City Tour”. That is the original get_title(). With Yoast I change this for use outside of my website to “%%title%% with %%sitename%% on %%event_date%%.”
How do I echo the altered output to the <head> of is_singular(‘event’)?
- The topic ‘Get Yoast meta outside of the loop?’ is closed to new replies.