Rishabh
Rishabh

Reputation: 650

Title (<title>) of wordpress site is not proper

In wordpress title of the page is divided by |. In my project On my front page title is fine (e.g. title | title). But in the inner pages title is not complete. Its not showing second part after | (symbol).

I have tried

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

But it does not show anything after | symbol (in inner pages).

I have also tried wp_title(). But its start showing url in the title instead of name/title. What else I can try to make my title correct

Upvotes: 1

Views: 340

Answers (3)

Rishabh
Rishabh

Reputation: 650

I have fond a solution with the help of THIS POST

Just did little bit changes in the solution of that post and its working fine now.

<title><?php if (is_front_page()) { bloginfo('name');echo ' | ';bloginfo('description'); } elseif ( is_category() ) { single_cat_title(); echo ' - ' ; bloginfo('name'); }
elseif (is_single() ) { single_post_title(); }
elseif (is_page() ) { bloginfo('name'); echo ' | '; single_post_title(); }
else { wp_title('',true); } ?></title>

Upvotes: 0

dingo_d
dingo_d

Reputation: 11670

From codex:

<?php
    if ( ! function_exists( '_wp_render_title_tag' ) ) :
        function theme_slug_render_title() {
        ?>
            <title><?php wp_title( ' ', true, 'right' ); ?></title>
            <?php
        }
        add_action( 'wp_head', 'theme_slug_render_title' );
    endif;
?>

Since Version 4.1, themes should use add_theme_support() in the functions.php file in order to support title tag, like so:

Upvotes: 2

DACrosby
DACrosby

Reputation: 11440

Your code

  1. Prints the name of your website
  2. Prints a pipe (|)
  3. a. If it's the home page, it prints the description of your website (“Tagline” set in Settings > General)
  4. b. If not, it prints the title of the current page

If it's printing {blog_title} | {blank} it most likely means something is wrong with the Page title. In the WP Admin, ensure the Page you're viewing has a Title set.

Alternatively, an SEO plugin is conflicting with the title function - try disabling plugins one by one and see if it impacts the output.

References: Bloginfo, is_front_page, wp_title

Upvotes: 2

Related Questions