Show SEO Title in the frontend
-
Hello,
I’m trying to show SEO title in the frontpage.
Tried this:function page_title_sc(){ $yoast_title = get_post_meta(get_queried_object_id(), '_yoast_wpseo_title', true); $title = strstr($yoast_title, '%%', true); if (empty($title)) { $title = get_the_title(get_queried_object_id()); } $wpseo_titles = get_option('wpseo_titles'); $sep_options = WPSEO_Option_Titles::get_instance()->get_separator_options(); if (isset($wpseo_titles['separator']) && isset($sep_options[$wpseo_titles['separator']])) { $sep = $sep_options[$wpseo_titles['separator']]; } else { $sep = '-'; } $site_title = get_bloginfo('name'); $meta_title = $title . ' ' . $sep . ' ' . $site_title; echo $meta_title; } add_shortcode( 'page_title', 'page_title_sc' );
It returns Page title for every single page.
Tried this too:
function yoastVariableToTitle($post_id) { $yoast_title = get_post_meta($post_id, '_yoast_wpseo_title', true); $title = strstr($yoast_title, '%%', true); if (empty($title)) { $title = get_the_title($post_id); } return $title; } // added this line below to show shortcode add_shortcode( 'product_seo_title', 'yoastVariableToTitle' );
Same thing happens.
Could you help me? ??
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Show SEO Title in the frontend’ is closed to new replies.