且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从我的 Wordpress 插件内部更改 wp_title

更新时间:2023-11-30 23:03:28

在 functions.php 中使用 is_page 不起作用,因为它在 wp 知道将要呈现的页面之前运行,甚至如果它是一个页面开始.将 is_page() 放在函数中,它应该可以工作.喜欢:

Using is_page in functions.php doesn't work, as it runs before wp knows what page it's going to render, or even if it's a page to begin with. Stick the is_page() inside the function, and it should work. Like:

function wp_myplugin_property_title()
{ 
  if( is_page('details') ){
    $wp_acquaint_id = get_option("wp_system_id");
    $propid = get_query_var('propid');
    if(isset($propid)){
        $seotitle = wp_myplugin_seo_title($propid);
    }else{
        $seotitle = "TEST Title";   
    }
    return $seotitle;   
  }
}


add_filter('wp_title', wp_myplugin_property_title, 100);