0

I want to keep the title and description of wordpress blog like this: Title | Description (showed in a tab of navigator). And I don't want to change his name while I am surfing the site.

I think that changing a little header.php could be solution but is bad option change a file directly. Only I know that title is here:

Any idea or advice?

6
  • 1
    You can use a child theme where you clone the header.php, and edit it as you want, in this case the tag <title>. It would be a safe solution, and useful for future changes. Commented Oct 7, 2014 at 8:58
  • 2
    Or you could filter the title and description from your child themes functions file. Commented Oct 7, 2014 at 9:04
  • Which option is better for quick of site load? Child theme?
    – Neil
    Commented Oct 7, 2014 at 10:07
  • If you are only concerned with the item in your navigation menu, just go to Appearance > Menu in your admin panel and change the Navigation Label to match your site's title and description.
    – iyrin
    Commented Oct 7, 2014 at 11:23
  • I just realized "navigator" in this question is referring to the browser and this question is asking about filtering how the title is displayed in the Title Bar. Disregard my previous suggestion. ^_^
    – iyrin
    Commented Oct 7, 2014 at 11:33

2 Answers 2

3

In any properly coded theme the title should be completely generated with wp_title() and easily filterable to specific string (in functions.php or otherwise):

add_filter( 'wp_title', function () {
    return get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'description' );
} );
5
  • Good answer, although you should metion that anonymous functions are available only in some versions of php.. Commented Oct 7, 2014 at 11:08
  • 6
    @DanielGarciaSanchez no. PHP 5.2 was last version without closures and it had been unsupported for more than three years now. If someone chooses to use it — it's their problem, not everyone's problem. :)
    – Rarst
    Commented Oct 7, 2014 at 11:13
  • Aha, then it's perfect :-) It was only a tip Commented Oct 7, 2014 at 11:17
  • 1
    Neil: One advantage of this method is that you can use it in a plugin instead of a theme file. This way you can change themes and it will still be applied. Writing a Plugin
    – iyrin
    Commented Oct 7, 2014 at 11:54
  • 1
    Thanks @Rarst and @RyanLoremIpsum for your help. Finally I changed a little because it appears 'Title | Title | Description'. I only deleted the blog info name: add_filter( 'wp_title', function () { return get_bloginfo( 'description' ); } ); And all works fine! :)
    – Neil
    Commented Oct 8, 2014 at 14:05
1

As an alternative to filtering, this method would be used to replace <title><?php wp_title(); ?></title> in your header.php file (ideally in a child theme).

bloginfo('name','description'); will display the site title and description.

From Function Reference/bloginfo

  • 'name' - Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table.
  • 'description' - Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the
    wp_options table.

Here's an example given for displaying title and description in the title section of your header.php:
<title><?php bloginfo('name','description'); ?></title>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.