Ad

Changing Yoast Title Using Wpseo_title Function

- 1 answer

I'm trying to set the title of the page (made by custom theme) This is my code, but for some reason it not getting the "$forumId" parameter

$forumId=999;
add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title() {
        return 'My id= '. $forumId  ;
}
Ad

Answer

You need to set $forumId as global variable. See updated code below.

global $forumId;
$forumId=999;
add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title() {
        global $forumId;
        return 'My id= '. $forumId  ;
}
Ad
source: stackoverflow.com
Ad