我'm wondering if it'可以替换页面 Headers 中的 "|" 中的 "-" .
"|"
"-"
例如,如果我有一个名为 "about" 的页面,它会显示 "SITENAME - About" ,我想将其更改为 "SITENAME | About .
"about"
"SITENAME - About"
"SITENAME | About
这取决于您如何获得主题中的 Headers . 如果主题只是使用类似get_the_title()的东西,则可以使用简单的字符串替换 .
<?php echo str_replace('-', '|', get_the_title()) ?>
您可以使用 wp_title hook来根据需要更改网站 Headers . AN将此代码放在 functions.php 文件中 .
wp_title
functions.php
add_filter( 'wp_title', 'my_new_site_title', 10, 2 ); function my_new_site_title($title) { $title = get_bloginfo('name').'|'.$title; return $title; }
或者您也可以使用 add_filter() 过滤器 the_title .
add_filter()
the_title
function my_filter_wp_title( $title ) { $custom_title = get_bloginfo('name').'|'.$title; return $custom_title; } add_filter( 'the_title', 'my_filter_wp_title' );
在 <head> 标记上添加此项
<head>
<title><?php wp_title('-',true,'right'); ?> <?php bloginfo('name'); ?></title>
3 回答
这取决于您如何获得主题中的 Headers . 如果主题只是使用类似get_the_title()的东西,则可以使用简单的字符串替换 .
您可以使用
wp_title
hook来根据需要更改网站 Headers . AN将此代码放在functions.php
文件中 .或者您也可以使用
add_filter()
过滤器the_title
.在
<head>
标记上添加此项