View Single Post
Old 08-05-2007, 02:25 PM   #3 (permalink)
a web apart
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.
a web apart is offline   Reply With Quote