宣威市网站建设,拓者网室内设计官网app,wordpress恢复备份,备案的网站每年都要备案么WordPress 4.4.0 版本开始#xff0c;加入了 wp_get_document_title(); 这个函数#xff0c;而 wp_title(); 已经 deprecated 不推荐使用。因此#xff0c;如果想要启用 WordPress 主题标题功能#xff0c;在不安装 WordPress SEO 插件的情况下#xff0c;可以使用以下代码… WordPress 4.4.0 版本开始加入了 wp_get_document_title(); 这个函数而 wp_title(); 已经 deprecated 不推荐使用。因此如果想要启用 WordPress 主题标题功能在不安装 WordPress SEO 插件的情况下可以使用以下代码即可function theme_support_title_setup() {add_theme_support( title-tag );
}
add_action( after_setup_theme, theme_support_title_setup );反之如果主题使用了 add_theme_support( title-tag ); 功能想要取消 WordPress 主题标题功能可以使用以下代码即可remove_action( wp_head, _wp_render_title_tag, 1 );如果不想取消 WordPress 主题标题功能又想自定义某些页面 SEO 标题信息可以使用以下过滤器。document_title_separatordocument_title_separator 过滤器来设定标题之间的分隔符。假设想要修改网站名称和标题之间的分隔符为“|”可以使用以下代码即可function custom_document_title_separator() {$separator | ;return $separator;
}
add_filter(document_title_separator, custom_document_title_separator);document_title_partsdocument_title_parts 过滤器来设定文档标题的其他组成部分通过关联数据传递。例如首页标题默认是 “网站名称 - 网站描述” 的形式如果你不想要网站描述可以删除数组中的 tagline。
function document_title_remove_tagline( $title ){if( is_home() isset( $title[tagline] ) ) {unset( $title[tagline] );}return $title;
}
add_filter( document_title_parts, document_title_remove_tagline );假如你想要改变标题对于网站分隔符和名称都继续保留可以使用以下代码function custom_site_seo_title( $title ) {$title[title] 自定义页面 SEO 标题return $title;
}
add_filter(document_title_parts, custom_site_seo_title, 10, 1);pre_get_document_titlepre_get_document_title 检查 wp_get_document_title() 是否返回任何东西而不是一个空值。示例代码function remove_site_desc_title_home( $title ){if ( is_home() || is_front_page() ) {$title get_bloginfo( name );}return $title;
}
add_filter( pre_get_document_title, remove_site_desc_title_home );p_get_document_title()wp_get_document_title(); 相当于 WordPress 4.4.0 之前的 wp_title(); 功能返回当前页面的文档标题。基础用法如下headmeta charset?php bloginfo( charset ); ?meta nameviewport contentwidthdevice-width /title?php echo wp_get_document_title(); ?/title?php wp_head(); ?
/head