More WordPress title modification

Some time ago I wrote about re-working WordPress titles to make them easier to read, and more search engine-friendly.

Since then I’ve done a bit more work on WordPress, and so I thought I’d share a few WordPress title modications I’ve used in a recent project.

I’m also going to throw in some

modifications, since

and </code> contents are fairly similar.</p> <h3>The <code><title></code></h3> <p><a href="http://twoseven.co.nz/2007/02/15/wordpress-titles/" title="twoseven.co.nz: WordPress titles">Read this first</a>. </p> <p>You got that? Good.<br /> Okay, so what I did was take the reshuffled code, as follows:</p> <p><code><title><br /> <?php wp_title(' '); ?> <?php if(wp_title(' ', false)) { echo ' - '; } ?> <?php bloginfo('name'); ?><br />

… and prepended a piece of code to check if this is a search page, and if so, show the search query, like this: Search for "" -

So we get:

<br /> <?php if (is_search()){ ?> Search for "<?php the_search_query(); ?>" - <?php } ?> <?php wp_title(' '); ?> <?php if(wp_title(' ', false)) { echo ' - '; } ?> <?php bloginfo('name'); ?><br />

So if you did a search for “free iPhones”, your browser’s title bar would show:

“Search for “Free iPhones” – Your Site Name”

It’s nothing amazing, but just makes the </code> that much more useful.</p> <h3>The <code></p> <h1></code></h3> <p>This is a unique title for a given page.<br /> There should be — according to me, anyway — just one <code></p> <h1></code> element per page.</p> <p>Here’s some code to look at:</p> <p><code></p> <h1><?php if (!is_home()) { ?><a href="<?php echo get_bloginfo('url'); ?>" title="Back to the home page"><?php if (is_search()){ ?> Search for "<?php the_search_query(); ?>" - <?php } ?><?php wp_title(' '); ?><?php if(wp_title(' ', false)) { echo ' - '; } ?><?php bloginfo('name'); ?></a><?php } else { bloginfo('name'); } ?></h1> <p></code></p> <p>Well, that’s rather hard on the eyes, isn’t it? One day I’ll move this blog off the default WordPress template and onto something that makes code chunks look better.</p> <p>It’s all wrapped in an ‘if’ statement that checks to see if this is the home page. If it is, then the <code></p> <h1></code> contains just the name of the site:<br /> <code>bloginfo('name');</code></p> <p>If this is not the home page, then the <code></p> <h1></code> element contains the page title as per the <code><title></code> element above, wrapped in an <code><a></code> element that links back to the home page:<br /> <code><?php if (!is_home()) { ?><a href="<?php echo get_bloginfo('url'); ?>" title="Back to the home page"> ... title code ... </a><?php } else { bloginfo('name'); } ?></code></p> <p>So there you have it.</p> <p>Again, I’m sorry this is so hard to read; maybe one day I’ll go into a bit more detail.<br /> Let me know if anything here requires further clarification.</p> </div><!-- .entry-content --> <div class="entry-utility"> This entry was posted in <a href="https://twoseven.co.nz/category/coding/" rel="category tag">Coding</a>, <a href="https://twoseven.co.nz/category/wordpress/" rel="category tag">Wordpress</a>. Bookmark the <a href="https://twoseven.co.nz/2007/09/11/more-wordpress-title-modification/" title="Permalink to More WordPress title modification" rel="bookmark">permalink</a>. </div><!-- .entry-utility --> </div><!-- #post-## --> <div id="nav-below" class="navigation"> <div class="nav-previous"><a href="https://twoseven.co.nz/2007/09/11/refurbished-iphones/" rel="prev"><span class="meta-nav">←</span> Refurbished iPhones</a></div> <div class="nav-next"><a href="https://twoseven.co.nz/2007/09/12/iphone-software-sim-unlock-done/" rel="next">iPhone software SIM unlock: done. <span class="meta-nav">→</span></a></div> </div><!-- #nav-below --> <div id="comments"> <div id="respond" class="comment-respond"> <h3 id="reply-title" class="comment-reply-title">Leave a Reply <small><a rel="nofollow" id="cancel-comment-reply-link" href="/2007/09/11/more-wordpress-title-modification/#respond" style="display:none;">Cancel reply</a></small></h3> <form action="https://twoseven.co.nz/wp-comments-post.php" method="post" id="commentform" class="comment-form"> <p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p><p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p><p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" required='required' /></p> <p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="text" value="" size="30" maxlength="100" aria-describedby="email-notes" required='required' /></p> <p class="comment-form-url"><label for="url">Website</label> <input id="url" name="url" type="text" value="" size="30" maxlength="200" /></p> <p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" /><label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time I comment.</label></p> <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment" /> <input type='hidden' name='comment_post_ID' value='48' id='comment_post_ID' /> <input type='hidden' name='comment_parent' id='comment_parent' value='0' /> </p> </form> </div><!-- #respond --> </div><!-- #comments --> </div><!-- #content --> </div><!-- #container --> <div id="primary" class="widget-area" role="complementary"> <ul class="xoxo"> <li id="search-2" class="widget-container widget_search"><form role="search" method="get" id="searchform" class="searchform" action="https://twoseven.co.nz/"> <div> <label class="screen-reader-text" for="s">Search for:</label> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form></li><li id="text-7" class="widget-container widget_text"> <div class="textwidget">[instagram-feed]</div> </li> <li id="recent-posts-2" class="widget-container widget_recent_entries"> <h3 class="widget-title">Recent posts</h3> <ul> <li> <a href="https://twoseven.co.nz/2012/10/02/wheedle-what-went-wrong/">Wheedle: What went wrong?</a> </li> <li> <a href="https://twoseven.co.nz/2012/02/08/pears-create-your-own-pattern-library/">Pears: Create your own pattern library</a> </li> <li> <a href="https://twoseven.co.nz/2011/04/02/steve-lacy-what-larry-page-really-needs-to-do-to-return-google-to-its-startup-roots/">Steve Lacy: What Larry Page really needs to do to return Google to its startup roots</a> </li> <li> <a href="https://twoseven.co.nz/2011/04/01/best-of-swiss-web-2011/">Best of Swiss Web 2011</a> </li> <li> <a href="https://twoseven.co.nz/2011/02/18/javascript-decision-tree-tool/">JavaScript Decision Tree tool</a> </li> </ul> </li><li id="rss-10" class="widget-container widget_rss"><h3 class="widget-title"><a class="rsswidget" href="http://pinterest.com/twoseven/feed.rss"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="https://twoseven.co.nz/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://www.pinterest.com/twoseven/">My Pinterest feed</a></h3><ul><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397634940534/'>Untitled</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397634940533/'>Wonderful photograph. High 5 to this photographer. and no wings</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397634940532/'>Garage '71: Fotos</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397634935798/'>Untitled</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397630338316/'>This sunny guest house is a pared-back and elegant new addition to a family of buildings on the site.</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397630080969/'>1973 Porsche 911 2.7 RSH</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397629303488/'>Ferrari 250 SWB. It doesn't get much better than this.</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397628715591/'>Untitled</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397628683357/'>Untitled</a></li><li><a class='rsswidget' href='https://www.pinterest.com/pin/255016397628635372/'>null</a></li></ul></li> </ul> </div><!-- #primary .widget-area --> </div><!-- #main --> <div id="footer" role="contentinfo"> <div id="colophon"> <div id="footer-widget-area" role="complementary"> <div id="first" class="widget-area"> <ul class="xoxo"> <li id="text-2" class="widget-container widget_text"><h3 class="widget-title">About Dan Willis</h3> <div class="textwidget"><br /> <dl> <dt>Gmail/Gtalk:</dt> <dd>dan.willis</dd> <dt>Mobile:</dt> <dd>+64 21 623 923</dd> <dt>Twitter:</dt> <dd><a href="http://www.twitter.com/danw">danw</a></dd> </dl> <p>…read more <a href="/about/" title="About twoseven.co.nz" rel="about">about Dan</a>.</p> </div> </li><li id="text-4" class="widget-container widget_text"><h3 class="widget-title">Disclaimer thingy</h3> <div class="textwidget"><p>The opinions and views expressed in this blog are my own and do not necessarily represent those of my employer.</p></div> </li> </ul> </div><!-- #first .widget-area --> <div id="second" class="widget-area"> <ul class="xoxo"> <li id="tag_cloud-3" class="widget-container widget_tag_cloud"><h3 class="widget-title">Tag cloud</h3><div class="tagcloud"><a href="https://twoseven.co.nz/category/coding/" class="tag-cloud-link tag-link-13 tag-link-position-1" style="font-size: 16.084507042254pt;" aria-label="Coding (19 items)">Coding</a> <a href="https://twoseven.co.nz/category/commentary/" class="tag-cloud-link tag-link-6 tag-link-position-2" style="font-size: 22pt;" aria-label="Commentary (79 items)">Commentary</a> <a href="https://twoseven.co.nz/category/design/" class="tag-cloud-link tag-link-7 tag-link-position-3" style="font-size: 17.859154929577pt;" aria-label="Design (29 items)">Design</a> <a href="https://twoseven.co.nz/category/gadgets/" class="tag-cloud-link tag-link-9 tag-link-position-4" style="font-size: 15.887323943662pt;" aria-label="Gadgets (18 items)">Gadgets</a> <a href="https://twoseven.co.nz/category/javascript/" class="tag-cloud-link tag-link-14 tag-link-position-5" style="font-size: 11.647887323944pt;" aria-label="JavaScript (6 items)">JavaScript</a> <a href="https://twoseven.co.nz/category/link/" class="tag-cloud-link tag-link-10 tag-link-position-6" style="font-size: 14.901408450704pt;" aria-label="Link (14 items)">Link</a> <a href="https://twoseven.co.nz/category/meetup/" class="tag-cloud-link tag-link-12 tag-link-position-7" style="font-size: 8pt;" aria-label="Meetup (2 items)">Meetup</a> <a href="https://twoseven.co.nz/category/meta/" class="tag-cloud-link tag-link-3 tag-link-position-8" style="font-size: 10.169014084507pt;" aria-label="Meta (4 items)">Meta</a> <a href="https://twoseven.co.nz/category/search-engineering/" class="tag-cloud-link tag-link-15 tag-link-position-9" style="font-size: 9.1830985915493pt;" aria-label="Search Engineering (3 items)">Search Engineering</a> <a href="https://twoseven.co.nz/category/tools/" class="tag-cloud-link tag-link-11 tag-link-position-10" style="font-size: 16.084507042254pt;" aria-label="Tools (19 items)">Tools</a> <a href="https://twoseven.co.nz/category/user-interface/" class="tag-cloud-link tag-link-8 tag-link-position-11" style="font-size: 14.211267605634pt;" aria-label="User Interface (12 items)">User Interface</a> <a href="https://twoseven.co.nz/category/web-standards/" class="tag-cloud-link tag-link-5 tag-link-position-12" style="font-size: 14.605633802817pt;" aria-label="Web Standards (13 items)">Web Standards</a> <a href="https://twoseven.co.nz/category/wordpress/" class="tag-cloud-link tag-link-4 tag-link-position-13" style="font-size: 11.647887323944pt;" aria-label="Wordpress (6 items)">Wordpress</a></div> </li> </ul> </div><!-- #second .widget-area --> <div id="third" class="widget-area"> <ul class="xoxo"> <li id="linkcat-16" class="widget-container widget_links"><h3 class="widget-title">Regular reads</h3> <ul class='xoxo blogroll'> <li><a href="http://cameronmoll.com/">Cameron Moll</a></li> <li><a href="http://simplebits.com/">Dan Cederholm : Simplebits</a></li> <li><a href="http://mezzoblue.com/">Dave Shea : Mezzoblue</a></li> <li><a href="http://stopdesign.com/">Douglas Bowman : Stopdesign</a></li> <li><a href="http://www.crockford.com/">Douglas Crockford's Wrrrld Wide Web</a></li> <li><a href="http://www.dustindiaz.com/">Dustin Diaz</a></li> <li><a href="http://airbagindustries.com/">Greg Storey : Airbag Industries</a></li> <li><a href="http://cognition.happycog.com/">Happy Cog's Cognition</a></li> <li><a href="http://kottke.org">Jason Kottke</a></li> <li><a href="http://jasonsantamaria.com/">Jason Santa Maria</a></li> <li><a href="http://jeffcroft.com/">Jeff Croft</a></li> <li><a href="http://www.zeldman.com/">Jeffrey Zeldman</a></li> <li><a href="http://snook.ca/jonathan/">Jonathan Snook</a></li> <li><a href="http://www.37signals.com/svn/">Signal vs. Noise (37 Signals blog)</a></li> <li><a href="http://stevesouders.com/">Steve Souders – High Performance Web Sites</a></li> </ul> </li> </ul> </div><!-- #third .widget-area --> <div id="fourth" class="widget-area"> <ul class="xoxo"> </ul> </div><!-- #fourth .widget-area --> </div><!-- #footer-widget-area --> <div id="site-info"> <a href="https://twoseven.co.nz/" title="Two Seven" rel="home"> Two Seven </a> </div><!-- #site-info --> <div id="site-generator"> <a href="http://wordpress.org/" title="Semantic Personal Publishing Platform" rel="generator">Proudly powered by WordPress.</a> </div><!-- #site-generator --> </div><!-- #colophon --> </div><!-- #footer --> </div><!-- #wrapper --> <script type='text/javascript' src='https://twoseven.co.nz/wp-includes/js/wp-embed.min.js?ver=5.2.2'></script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-279888-7']); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </body> </html>