• Resolved metdark

    (@metdark)


    The codes below works in changing title and meta description by query strings. There was only one page with 3 query strings. The other pages do not have query strings. With the codes in functions.php, the other pages Yoast title and metadescription does not work properly. Without the codes, Yoast title and meta description works properly. Is there a way to make the codes work while still using Yoast title and meta description?

    /* Changing title and meta description by query strings */
    function yoast_add_title (){
        if ( ! empty( $_GET[ 'q' ] ) && $_GET['q'] == 'medical' ) {
            $title = 'Health';
        }
        if ( ! empty( $_GET[ 'q' ] ) && $_GET['q'] == 'wealth' ) {
            $title = 'Financial';
        }
        if ( ! empty( $_GET[ 'q' ] ) && $_GET['q'] == "retirement" ) {
            $title = 'Wealth';
        }
        return $title; 
    }
    
    function yoast_add_metadesc (){
        if ( ! empty( $_GET[ 'q' ] ) && $_GET['q'] == 'medical' ) {
            $metadesc = 'Health';
        }
        if ( ! empty( $_GET[ 'q' ] ) && $_GET['q'] == 'wealth' ) {
            $metadesc = 'Financial';
        }
        if ( ! empty( $_GET[ 'q' ] ) && $_GET['q'] == "retirement" ) {
            $metadesc = 'Wealth';
        }
        return $metadesc; 
    }
    
    add_filter( 'wpseo_title', 'yoast_add_title', 10, 1);
    add_filter( 'wpseo_metadesc', 'yoast_add_metadesc', 10, 1);
    • This topic was modified 6 years ago by metdark. Reason: title too long
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    We can’t offer support on custom code (needed to change (core) features of our plugin). 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.

    Thread Starter metdark

    (@metdark)

    The code below works in functions.php instead. Somehow I need to target the exact page id and use template_redirect.

    function yoast_add_title (){
        if ( $_GET['q'] == 'medical' ) {
            $title = 'Health';
        }
        if ( $_GET['q'] == 'wealth' ) {
            $title = 'Financial';
        }
        if ( $_GET['q'] == 'retirement' ) {
            $title = 'Wealth';
        }
        return $title;
    }
    
    function yoast_add_metadesc (){
        if ( $_GET['q'] == 'medical' ) {
            $metadesc = 'Health';
        }
        if ( $_GET['q'] == 'wealth' ) {
            $metadesc = 'Financial';
        }
        if ( $_GET['q'] == 'retirement' ) {
            $metadesc = 'Wealth';
        }
        return $metadesc; 
    }
    
    function yoast_add_all (){
        if ( is_page(50) && ( ! empty( $_GET[ 'q' ] ) ) ) { 
            add_filter( 'wpseo_title', 'yoast_add_title', 10, 1 );
            add_filter( 'wpseo_metadesc', 'yoast_add_metadesc', 10, 1 );
        }
    }
    
    add_action( 'template_redirect', "yoast_add_all" );
    Plugin Support Michael Tiña

    (@mikes41720)

    Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code that is out of the core features of the Yoast SEO plugin, we cannot advise you on how to make such changes.

    If your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview. Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Yoast normal title and meta description no longer works when using wpseo api’ is closed to new replies.