Extra Words In Title Tag Recipe

Summary: This is a really simple recipe for adding extra words to the title tag in the head.
Version: 1.0.20090707
Prerequisites: TBC
Status: Functional, tested on 2.2.0-beta67
Maintainer: AndyG
Categories: CMS, Administration, PHP72

Questions answered by this recipe

I want to add extra words or phrases to the head->title tag but I don't want these to be shown in the title as it is displayed in the page, how can I do this?

Description

Recipe that allows you to adding extra words to the title tag in the html head tag but not title page text.

Notes

This is a really simple recipe for adding extra words to the title tag in the head. It is intended for use with SEO, so you want the head->title tag to have extra words in it that are not in the title text in the body of the page.

Most search engines put a high value on the title tag when deciding relevance to search terms, it is, I think the simplest and most effective SEO option.

It's a bit daft having a separate file for it as it is only a few lines of code, but it's better for maintenance that way really.

Instructions

  1. Upload extrawordsintitletag.phpΔ to your /cookbook/ folder.
  2. Add include_once("$FarmD/cookbook/extrawordsintitletag.php"); to your /local/config.php or /local/farmconfig.php.
  3. Add (:ExtraTitleWords blah blah blah:) to the text of your page. This will apend your title with ", blah blah blah". If the ExtraTitleWords markup is not used, your page title will just display as normal.

Code

as there is not much code, I'll paste in in here for ease of understanding.

 $RecipeInfo['Extra Words In Title Tag']['Version'] = '1.0.20090707';

 Markup("ExtraTitleWords", "directives", '/\\(:ExtraTitleWords (.*?):\\)/e', 'fExtraTitleWords("$1")');

 function fExtraTitleWords ($extrawordstring) {
  // take the title and add the extrawordstring to the end after a comma.
  $GLOBALS["WikiTitle"] .= $GLOBALS["WikiTitle"] . ", " . $extrawordstring;
 }

Update for PHP 5.5 & 7.2:

 Markup("ExtraTitleWords", "directives", '/\\(:ExtraTitleWords (.*?):\\)/', 'fExtraTitleWords');

 function fExtraTitleWords ($extrawordstring) {
  // take the title and add the extrawordstring to the end after a comma.
  $GLOBALS["WikiTitle"] .= $GLOBALS["WikiTitle"] . ", " . $extrawordstring[1];
 }

Release notes

1.0.20090707 released 7th of July 09.

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Contributors

Comments

See discussion at ExtraWordsInTitleTag-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.