2016-12-07 67 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; 
}