首页 文章

Wordpress - 如何在页面 Headers 中的“|”中替换“ - ”

提问于
浏览
0

我'm wondering if it'可以替换页面 Headers 中的 "|" 中的 "-" .

例如,如果我有一个名为 "about" 的页面,它会显示 "SITENAME - About" ,我想将其更改为 "SITENAME | About .

3 回答

  • 0

    这取决于您如何获得主题中的 Headers . 如果主题只是使用类似get_the_title()的东西,则可以使用简单的字符串替换 .

    <?php echo str_replace('-', '|', get_the_title()) ?>
    
  • 0

    您可以使用 wp_title hook来根据需要更改网站 Headers . AN将此代码放在 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 .

    function my_filter_wp_title( $title ) {    
    
        $custom_title = get_bloginfo('name').'|'.$title;
    
        return $custom_title;
    }
    add_filter( 'the_title', 'my_filter_wp_title' );
    
  • 0

    <head> 标记上添加此项

    <title><?php wp_title('-',true,'right'); ?> <?php bloginfo('name'); ?></title>
    

相关问题