scriptygoddess

16 Mar, 2010

SEO Plugins and problems with the titles not rewriting (WordPress)

Posted by: Jennifer In: WordPress|WordPress Hacks

I can't speak for anyone else who has run into this problem, but I know I have run into it on more than one occasion. Having just figured out my particular issue this time, I'm making a note for myself (and anyone else who may have the same problem).

You may run into this problem if you have a template that you have "hardcoded" the header (in my case – it was a custom page template that actually needed a completely different header than the rest of the site – so I opted not to use "get_header()" on this template and just put the custom header right there in my custom page template…)

I *did* remember to include the "wp_head()" – so that wasn't the issue (although I have fogotten to do that on other occasions and that will cause all kinds of trouble, including seo plugin stuff not working) – but in this case – the other meta tags were coming in – but the titles weren't being rewritten.

The problem was the fact that I wasn't using get_header() – this must be the function that kicks off the search for that title tag and replaces it with the rewritten titles. If you don't use get_header() – your titles will not be rewritten.

You will run into the same problem even if you don't "hardcode" your header – and use the "include" line instead:

include( TEMPLATEPATH . '/header2.php' );

Whatever happens with "get_header()" – you need to run it to get those titles working.

(I've since updated this post – scroll down to the bottom for the simplest solution!!)
So if you have a different header for your page template – what you need to do is within your header.php – determine which header file it should load in… but ONLY AFTER you have the title tags written out… You could even use the "is_page_template()" function to figure out which header to pull in.

So my header.php looked something like this for this project I was running into with this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<?php
if (is_page_template('my-custom-page-template1.php') || is_page_template('my-custom-page-template2.php')) {
include( TEMPLATEPATH . '/my-custom-page-template-header.php' );
} else {
?>
... rest of the header is here...
<?php } // endif custom page template checking... ?>

Now you can put your custom header in that "my-custom-page-template-header.php" (or whatever you want to call it) and on your "my-custom-page-template1.php and my-custom-page-template2.php, etc just use get_header() at the top like normal.

Actually – here's an even better/simpler option:

Name your custom header like this:
header-my-customheader.php.

Then when you call "get_header()" – do so like this:

get_header('my-customheader');

1 Response to "SEO Plugins and problems with the titles not rewriting (WordPress)"

1 | Michael

March 16th, 2010 at 12:26 pm

Avatar

You can use get_header(2) in your case. The filename of your custom header has to be header-2.php.

The problem with include(your_file.php) is, all the globals are not set.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements