2016-12-07 70 views
1

我试图改变添加变量(产品品牌)的标题标记,但变量不显示。使用过滤器更改标题标记wpseo_title

add_filter('wpseo_title', 'filter_product_wpseo_title'); 
    function filter_product_wpseo_title() { 
     return 'hello'. $_GET[$mysite_slugs['product-brand']] .'hello'; 
    }; 
} 

也试过,但没有运气

add_filter('wpseo_title', 'filter_product_wpseo_title'); 
    function filter_product_wpseo_title() { 
      $productbrand = $_GET[$mysite_slugs['product-brand']]; 
      return 'hello'. $productbrand .'hello'; 
    }; 
} 

回答

0

我假设你的URL有参数.com/?product-brand=foo。确保您已将优先级添加到您的过滤器。这应该做的伎俩!

add_filter('wpseo_title', 'filter_product_wpseo_title', 10, 1); 

function filter_product_wpseo_title($title) { 
    $title = 'hello '. $_GET['product-brand'] .' hello'; 
    return $title; 
}