Go Back   Internet Business Forums > Webmasters

Reply
 
Thread Tools Display Modes
Old 07-05-2007, 02:11 PM   #1 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,719
Default Wordpress titles without junk

One thing I find really annoying about Wordpress - the default page titles.

From a SEO standpoint, you really just want the page name in the title - but Wordpress throws in Site name >> Page Name.

It should be simple to edit - after all, the default Wordpress title appears as:

Code:
<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
So what it you remove bloginfo from the title, ie?

Code:
<title><?php wp_title(); ?></title>
Then your page titles become an annoying:

>> Page Title

Here's the fix:

Code:
<title><?php wp_title(($sep = '')); ?></title>
By using this, you tell Wordpress to only display the page title as the actual title - as before - but with the small tweak of declaring that you do not want a separator (ie, &raquo; ) in there.

So apply that you end up with:

Page Title

as your title.

A very simple, but bloody useful tip.

Thanks to Bruce Lawson for that, and there are a few more small - but useful - editing tweaks here:
http://www.brucelawson.co.uk/2005/wo...ibility-hacks/


ADDED: Okay, that removes the blog name from the index page. Damn. Need to find an expression to allow wp_title in posts AND categories, while allow for bloginfo in the index.

Otherwise, a simple work around:

Code:
<title><?php wp_title($sep = ''); ?>: <?php bloginfo('name'); ?></title>
Which displays:

Page title: Blog name
__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Old 08-05-2007, 10:13 AM   #2 (permalink)
Junior Member
 
Join Date: Apr 2007
Posts: 4
Default Re: Wordpress titles without junk

Quote:
Originally Posted by Brian Turner View Post
One thing I find really annoying about Wordpress - the default page titles.

From a SEO standpoint, you really just want the page name in the title - but Wordpress throws in Site name >> Page Name.

It should be simple to edit - after all, the default Wordpress title appears as:

Code:
<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
So what it you remove bloginfo from the title, ie?

Code:
<title><?php wp_title(); ?></title>
Then your page titles become an annoying:

>> Page Title

Here's the fix:

Code:
<title><?php wp_title(($sep = '')); ?></title>
By using this, you tell Wordpress to only display the page title as the actual title - as before - but with the small tweak of declaring that you do not want a separator (ie, &raquo; ) in there.

So apply that you end up with:

Page Title

as your title.

A very simple, but bloody useful tip.

Thanks to Bruce Lawson for that, and there are a few more small - but useful - editing tweaks here:
http://www.brucelawson.co.uk/2005/wo...ibility-hacks/


ADDED: Okay, that removes the blog name from the index page. Damn. Need to find an expression to allow wp_title in posts AND categories, while allow for bloginfo in the index.

Otherwise, a simple work around:

Code:
<title><?php wp_title($sep = ''); ?>: <?php bloginfo('name'); ?></title>
Which displays:

Page title: Blog name
Theres a plugin on the main Wordpress site that does all this for you - well you provide the bespoke paramaters, or else it defaults to your example at the top
PeteYoung is offline   Reply With Quote
Old 08-05-2007, 02:25 PM   #3 (permalink)
Member
 
a web apart's Avatar
 
Join Date: May 2007
Location: Wellingborough, Northants
Posts: 4
Default Re: Wordpress titles without junk

I don't know wordpress but I can offer my 2 cents on the PHP code. Apologies if I'm either stating the obvious or on the other hand blinding people with science, unfortunately I'm not yet aware of the levels of technical ability of people on this forum.

Firstly, I think there's a difference between:

1. wp_title(($sep = ''))

and

2. wp_title($sep = '')

the second version provides a named parameter value to the function, whereas the first version (I think, pretty sure) creates a local variable, assigns it a value of '', and the result of that assign (i.e. '') is passed as the first parameter to the function. So they both work, but the second version is correct.

As for a solution to the problem, an immediate if can be used to get an expression which returns one value if title is blank and another value if title is available. An immediate if is something like:

(condition) ? (value if condition is true) : (value if condition is false)

In this particular case:

Code:
<title><?php ( '' == trim(wp_title($sep='',$display=false)) ) ? bloginfo('name') : wp_title($sep=''); ?></title>
If title is blank then the blogname is used, otherwise the title is used.

Since both functions echo the result by default, the first call to wp_title in the condition part has to be told not to echo but return the result, I checked the wp_title function code and this is done with the $display=false parameter.
__________________
Paul, awebapart.com - 'a web apart'
UK ecommerce + business websites
a web apart is offline   Reply With Quote
Old 08-05-2007, 06:43 PM   #4 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,719
Default Re: Wordpress titles without junk

Paul, you're a star - just tested it out and works exactly as required.

(I never was very good with languages ... )
__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


All times are GMT +1. The time now is 05:55 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.