• Resolved cecowe

    (@cecowe)


    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)
  • Plugin Support devnihil

    (@devnihil)

    Unfortunately we can’t offer support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

    Closed. No other concerns.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show SEO Title in the frontend’ is closed to new replies.