WordPress wp_title blank on index page

后端 未结 12 900
刺人心
刺人心 2020-12-24 05:44

I\'m new to WordPress and just installed version 3.3.1.

I did some googling regarding this question and found some answers but they were relevant to version 2.7 and

相关标签:
12条回答
  • 2020-12-24 06:10

    Update for WordPress versions (>= 4.4)

    Try this

    function some_name(){
        add_theme_support( 'title-tag' );
    }
    
    add_action( 'after_setup_theme', 'some_name' );
    

    Do this in functions.php and remove 'title' tag from head...

    0 讨论(0)
  • 2020-12-24 06:14

    The new hack from Codex is as follows:

    <title><?php wp_title(''); ?></title>
    

    Then in your "functions.php" from theme file :

    add_filter( 'wp_title', 'baw_hack_wp_title_for_home' );
    function baw_hack_wp_title_for_home( $title )
    {
      if( empty( $title ) && ( is_home() || is_front_page() ) ) {
        return __( 'Home', 'theme_domain' ) . ' | ' . get_bloginfo( 'description' );
      }
      return $title;
    }
    
    0 讨论(0)
  • Here's is what I read from Codex:

    If you are using a custom homepage with custom loops and stuff, you will have an empty wp_title. Here goes a neat hack to add the description/tagline at the wp_title place on homepage:

    <title><?php bloginfo('name'); ?> | <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
    

    So use is_front_page() to get the title on homepage, the way it is suggested in above code.

    0 讨论(0)
  • 2020-12-24 06:19

    no need. Just add the <? Php wp_head ();?> Code at the end of the header.php

    good luck.

    0 讨论(0)
  • 2020-12-24 06:22

    But if you use a static home page, this is the code:

    <title><?php bloginfo('name'); ?> &raquo; <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
    
    0 讨论(0)
  • 2020-12-24 06:22

    I use this method in my WordPress site

    //Meta Header
    if ( ! function_exists( 'dima_wp_title' ) ) :
      function dima_wp_title( $title ) {
    
        if ( is_front_page() ) {
          return get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'description' );
        } elseif ( is_feed() ) {
          return ' | RSS Feed';
        } else {
          return trim( $title ) . ' | ' . get_bloginfo( 'name' ); 
        }
    
      }
      add_filter( 'wp_title', 'dima_wp_title' );
    endif;
    
    0 讨论(0)
提交回复
热议问题