Home > Web Design, WordPress > WordPress Wednesday: All-in-One SEO Without Using wp_head()

WordPress Wednesday: All-in-One SEO Without Using wp_head()

February 3, 2010

One of my favorite plugins to use for client sites is the All-in-One SEO Pack. I like how it allows me (or the client) to specify unique keywords, descriptions, menu text, etc. for each page or post on their site. I don’t like that it requires me to use the wp_head() function in order to edit keywords and descriptions.

For those who don’t know already, wp_head() automatically adds data to the header of your WordPress pages. Some of this data is helpful (like adding the descriptions and keywords from the All-in-One SEO Pack); some of it is not (like what version of WordPress your site uses, which helps hackers know which vulnerabilities they should try to exploit).

My workaround is to add a couple of simple php functions to my functions.php file. For example, the following function write the SEO Pack meta keywords into my WordPress page:

// function to insert All-in-One SEO Pack keywords
function keyword_insert() {
 global $post; // VERY important!

 // Retrieve keyword meta data from the SEO Pack
 $seokeywords = stripslashes(get_post_meta($post->ID, '_aioseop_keywords', true));

 // Default keywords in case none are specified for the page
 if (empty($seokeywords)) $seokeywords = "Homestar Runner, Strong Bad, The Cheat";

 // Output the html code
 $seokeyword_block = "<meta name=\"keywords\" content=\"".$seokeywords."\"/>\n";
 echo $seokeyword_block;
}

If I want to use the SEO Pack meta description, I alter the function like so:

// function to insert All-in-One SEO Pack description
function description_insert() {
 global $post; // VERY important!

 // Retrieve description meta data from the SEO Pack
 $seodesc = stripslashes(get_post_meta($post->ID, '_aioseop_description', true));

 // Default description in case none is specified for the page
 if (empty($seodesc)) $seodesc = "Oh! I am Homestar, and This is A Website!";

 // Output the html code
 $seodesc_block = "<meta name=\"description\" content=\"".$seodesc."\"/>\n";
 echo $seodesc_block;
}

If I wanted to create functions to pull additional information from the SEO Pack, they would also follow this same format. The different meta keys used by the All-in-One SEO Pack are:

  • _aioseop_keywords: meta keywords for the page; if your template already includes a <meta> keywords tag, the SEO Pack function will write a second tag — it is better to use one or the other and not both
  • _aioseop_description: meta description for the page; like the keywords, the SEO Pack function will write a second <meta> description if one is already included in the template
  • _aioseop_title: as in page title; the SEO Pack will rewrite any instances of the post title with this value unless you uncheck the “Rewrite Titles” option in the plugin settings; otherwise defaults to post title if no value is specified
  • _aioseop_menulabel: this is the text that is retrieved by the wp_list_pages() function; defaults to post title if no menu label is specified
  • _aioseop_titleatr: this is the “title” attribute for the links retrieved by the wp_list_pages() function; defaults to post title if no title attribute is specified

You will probably use the other meta keys less frequently than _aioseop_keywords and _aioseop_description since the other keys work through existing WordPress functions, although I have had use special functions for those keys on a few occasions.

Update: Silly me, I forgot to mention how to use these.

Place the following lines of code between the <head> and </head> tags in your template:

<?php description_insert(); ?>

<?php keyword_insert(); ?>

But then you probably already knew that.



Advertisements
  1. Bal
    May 22, 2010 at 6:58 AM

    Hi,
    I have installed and configured the all in one seo pack. My query is whether I can give the same set of phrases in the wordpress tags as well as the all in one seo keywords in the specific post. For instance, I have a post tiled “health benefits” and I have the wordpress tags “health”, “benefits”, “fitness”. I use the same phrases “health”, “benefits”, “fitness” in the keywords text box of the all in one seo plugin in the same post. Is it okay or does Google consider these tags as duplicate?
    – Bal

    • May 22, 2010 at 11:37 AM

      I think you get duplicates if you set the “Use Tags for META keywords” option and enter the keywords manually. Since Google ignores keywords this won’t technically hurt your search rankings, but it’s extra work on your part.

  2. Bal
    May 22, 2010 at 10:02 PM

    I can confirm I have left the “Use Tags for Meta keywords” UNCHECKED. However, I do enter the keywords manually. Am I not using the tool effectively then? Please explain how to use the plugin to generate keywords automatically. Perhaps I haven’t yet realized the power of this plugin as I am not very experienced in this area. Thanks in advance for your guidance.

    • August 10, 2010 at 11:54 AM

      I would say either check the “use tags for meta keywords” box OR enter your keywords manually. Either one will work fine for you. If you want to generate keywords automatically, then I would check the “use tags for meta keywords” box.

  3. August 8, 2010 at 2:34 AM

    I have a smilar query, if i want to use a phrase rather than a word for example buy clothes, then should my keyword bo look like this:?

    buy, clothes, buy clothes,

    Or do i need to add a – or ” to the buy clothes bit?

    • August 10, 2010 at 11:55 AM

      No need for hyphens or quotes — a search phrase is just fine. In the example you give, I would only use buy clothes as a phrase and not separately as buy, clothes.

  4. August 9, 2010 at 10:40 PM

    please can u tell me what is de wp_head reference i need tweak the wp_head call in my header i am searching in variuos sites but not results. Thanks

    • August 10, 2010 at 12:52 PM

      What are you trying to do?

  5. August 30, 2010 at 11:02 PM

    Thanks for this! I recently noticed that my pages had no keywords or meta descriptions despite that I enter them in manually in AIOSEO on WordPress 3.0. I think I have finally figured out that my problem was that my theme does not call wp_head. Your fixing for useing All-in-One SEO Without Using wp_head() is perfect. Thanks, again.

  6. September 14, 2010 at 3:33 AM

    Great, I will take your trick to my website

  7. November 16, 2010 at 6:44 PM

    implementing now,great deal check my blog if you get a moment ๐Ÿ™‚

  8. November 23, 2010 at 4:27 AM

    Thanks

    I love the plugin but it was a really pain to remove wordpresses own meta insertions

    Cheers.

  9. January 8, 2011 at 7:15 PM

    Awesome
    Thxs….. thank so much !!!

  10. June 20, 2011 at 3:44 PM

    Im having trouble with this… I used this in the functions.php:
    // function to insert All-in-One SEO Pack description
    function title_insert() {
    global $post; // VERY important!

    // Retrieve description meta data from the SEO Pack
    $seotitle = stripslashes(get_post_meta($post->ID, ‘_aioseop_title’, true));

    // Default description in case none is specified for the page
    if (empty($seotitle)) $seotitle = “Protech Alarms | Tucson (AZ)”;

    // Output the html code
    $seotitle_block = “\n”;
    echo $seotitle_block;
    }
    ———————
    I need to be able to rewrite the titles…

  11. kikeropallorski
    June 21, 2011 at 2:31 PM

    Iยดm using external pages with wp template and wp_head. Where should i put this in All-in-One SEO Pack?

  12. alex
    December 9, 2011 at 11:18 AM

    Thank you for the work. once removed the tag wp_head, and forgot about it. after completely redesigned site. and this work needed plugin All-in-One SEO Pack. but when add wp_head, design began to swim ๐Ÿ˜ฆ you solved this problem ๐Ÿ™‚ thanks! greetings from Ukraine!

  13. January 16, 2012 at 7:38 AM

    Hi Michael,

    this is an interesting tutorial! Thanks for sharing.

    I am using All in One SEO Pack but want to overide the output on some specific blogposts. The reason is, I am aggregation some Posts and therefore I can not customise the Meta Data individualy for aggregated post creation.

    But for this posts I have some data in custom field fubar. What I want to do:

    if custom field fubar has any value -> use “_post_title_ + _custum_keyword_ + _custom_field_fubar_” as Meta Title.

    if custom field fubar has any value -> use “_post_title_ + My custom Text” as Meta Description.

    I still want to leave the wp_head in my theme. Just want to overide the AIO SEO Pack output for some specific posts.

    I think I could do this simmilar like you described with the themes function.php but how to override the output?

    Thanks

  14. February 4, 2012 at 4:03 PM

    Hi, I used your tip to post keywords into the body because I want the keywords are the page h1, but I get the following:
    “Fatal error: Call to undefined function keyword_insert() in /web/htdocs/www.studioboselli.net/home/sito/wp-content/themes/care/care/header.php on line 27”
    In which functions.php file I need to insert your code?
    (I’m using the “care” premium themeforest plugin)

    Many thanks, Alessandro

  15. February 27, 2012 at 9:10 PM

    you save….. me. thanks for this code buddyy mwahhhh. and i know i can proceed. on my next task..

  16. vaclavambroz
    March 12, 2012 at 3:50 AM

    Hello, thanks for your script, but how do you solve description and keywords on homepage (index.php)? This in only for posts. Thank you.

  17. March 13, 2012 at 5:43 AM

    Hello again, I solve it for index.php too. You can see it here -> http://vaclavambroz.cz/wordpress-all-in-one-seo-pack/

  18. October 24, 2013 at 1:48 AM

    its very helpful

    can you help me what i can do with “qtranslate meta” without wp_head
    i will be appreciated

    • October 28, 2013 at 3:07 PM

      Mohammad – I’ve learned a lot since I first put up this post, and I wouldn’t recommend leaving out wp_head(). A better better practice is to use wp_head(), but use remove_action() to get rid of anything you don’t want printing out in your header. For example, to remove the WordPress version from your header, you could add the following to your functions.php file: remove_action( 'wp_head', 'generator' );.

      On a related note, I also don’t recommend All-in-One SEO anymore. Though I’m sure it’s a fine plugin, I personally prefer WordPress SEO by Yoast.

  1. March 30, 2010 at 12:20 PM
Comments are closed.
%d bloggers like this: