WordPress SEO without plugin for theme developers & SEO experts

seo-unpluginHow to implement custom Meta Descriptions, Meta Keywords, and Robot Meta Tags into your theme without using plugins and branding it as your own. Right off the bat, this post is not for regular WordPress users. This is for experienced theme developers and those who specifically can read and write PHP.

WordPress SEO seems to be the easiest thing to do with all the free plugins out there, and they make it look like that a monkey can get a good result as long as they use a high rated plugin. The problem that I have with almost all SEO plugins is the amount of garbage that comes with them or in some cases, the intentional link placing of the authors in the code to get your precious page-rank directed at their own sites. Take Yoast SEO Plugin for example. The author is so pompous and arrogant that in a discussion on wordpress.org, when many people asked him to remove his link from the source or give option for the user to do it, he uttered that “I’ll never offer a way to take them [links to his website] out via the back-end.”

I don’t know about you but if I spend my time optimizing a site, I sure as hell don’t like to give my hard earned ranking to someone else. And I take it even more seriously when it comes to my clients. They are paying good money for the best possible result, and by cutting corners and using garbage plugins, I would be cheating them, and that’s not OK in my book.

What I have put together here is a clean and easy way to implement Meta Descriptions, Meta Keywords, and Meta Robot Tags, into your posts, pages, archives, categories,… and also the means to set global keywords for all pages. I’ve written this code based on the excellent “Custom Metaboxes” library and not only you get perfect SEO functionality; you also get all the goodies of the Custom Metaboxes as well. A big thank you and truckload of credit goes to CMB developers; Bill Erickson, Jared Atchison, Andrew Norcross, and many others who’ve contributed to this great project.

So less get to the point. First download the complete source code in a zip format. When you extract the files, you’ll notice that there’s a directory called “lib” and two single files called “Insert into functions.php” and “Insert into header.php”. The “lib” folder goes inside your theme directory. (wp-content/themes/yourtheme/lib) and the rest is self explanatory. Copy the content of the “Insert into functions.php” into your theme’s function.php and the content of “Insert into header.php” into your header.php between the <head> tags and before your stylesheet and javascripts. That’s it, you’re done.

Make sure to remove all other meta description and keyword codes from the head if you have any. I’ve commented on every block of code so you can follow easily even if you’re not very PHP savvy.

Once you’ve installed the script, look under your “settings/general” in the WordPress admin and you’ll see another field for Global keywords. Fill in your desired keywords and proceed to individual posts and pages.

The result will look like the following on every page and post. (If you have custom post types, no problem, just add your post type to the function code and you’re done)


So instead of confusing your clients and yourself with million useless options, do it right the first time and have your theme SEO ready. Even if the client doesn’t enter anything in the SEO box, Meta Description and Keywords will automatically be generated based on the site description, and global keywords.

Hope you like this little “un-plugin” and if you have any questions or comments, post them below.

29 Responses to WordPress SEO without plugin for theme developers & SEO experts

  1. ingenieurs marocains says:

    هيئة المهندسين التجمعيين – corps des ingenieurs du parti du RNI

    This is my expert

  2. Avatar for Alex Alex says:

    Hello Chris. Thank you for the great article. I’ve had enough trouble with lots of complex plugins that take too much processing power, so I decided to change course.

    Apologies for bringing up this old post. I’ve got a few questions for you.

    Does this method still work today, after so many WordPress and Google changes?
    Would you still recommend it over a seo plugin?

    I always write post titles and excerpts with attractive content that makes the user want to click and read the post. So, in my case, using the excerpt as a meta description and the post title as a meta title would be ideal, since I’ve got a user optimised text already there.
    How do I pull the excerpt to be placed in the position of the hand written ones (and remove the Meta Keywords and Meta Description fields completely, keeping only the Meta Robot Request?

    In regards to what Jacqueline asked above (Is there any way to set ‘noindex, nofollow’ to the author, category and archive pages), I can’t seem to figure out the exact code. Could you please give some more detail (or the actual code if that’s at all possible)?

    Apologies if I’m asking a lot and thank you for your time.

  3. Avatar for Wayan Cenik Wayan Cenik says:

    Great tutorial, one question : how to add the title manual using your tutorial

  4. Avatar for Cem ozturk Cem ozturk says:

    Hi Guys

    Not sure if anyone experienced this problem either, but after entering the above code into functions.php, my website has slowed down.


  5. Avatar for Veli Bilgilendirme Veli Bilgilendirme says:

    I want to let my users post on my site in near future but I don’t want them to get confused with SEO titles and meta description etc. So thanks for your help here.

  6. Avatar for dhoi dhoi says:

    @Chris :
    did you see the code I wrote in the above comment?
    in the code that I’ve succeeded on the is_front_page and is_category, but to call the custom seo for combining is_page & is_single & empty that meta desc is null.

    If I replace it with the code you wrote above, all meta desc be static all page ( call bloginfo description ).

    • Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

      I can’t see the code that you wrote as it got stripped out, but the code i gave you above will do what you need. When testing, make sure you have the meta boxes filled out as if you leave them empty, the blog description will be substituted.

  7. Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

    @dhoi: Here’s the code:

    <?php if (is_front_page() or (empty($DD_meta_description))) { ?>
    <meta name="description" content="<?php bloginfo('description'); ?>" />
    <?php } elseif (is_category()){ ?>
    <meta name="description" content="<?php echo category_description(); ?>" />
    <?php } else{ ?>
    <meta name="description" content="<?php echo $DD_meta_description; ?>" />
    <?php } ?>

    It checks to see if the page is a front page or has a empty meta description and it will put the blog description (under General settings) in the meta tag. If It’s not a front page or has meta description already, it checks to see if it’s a category and if it is, it outputs the category description, and lastly it if none of the above statements are true, it outputs the custom SEO.

    As I said before you need to trim the category description as there is no limit on it. Refer to this page for trimming character counts or the php manual.


  8. Avatar for dhoi dhoi says:

    hi chris, thanks for this script. but i have a question, how to add this meta for categories.

    • Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

      @dhoi: It’s not necessary, as WordPress category and archive pages don’t have any new information. You shouldn’t even include them in your xml sitemap. Category and archive pages are more for internal use to make navigation and searches easier.

      • Avatar for dhoi dhoi says:

        oh i see Chris, but now my index meta description field always showing the last post, how make it static for both ( description and keyword ). thanks again.

        • Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

          Add a conditional statement such as:

          <?php if( is_front_page() ) { ?>
          <meta name="description" content="<?php bloginfo('description'); ?>" />
          <?php } else {?> bala blah

          Above the first meta description statement.

          • Avatar for dhoi dhoi says:

            thanks for your reply Chris,
            i’m stuck with this, where my logic is, if front page custom meta description, if category will post category description and where is empty & page & single meta descripstion will post from $DD_meta_description. and i added conditional like this:

            <meta name="description" content="”/>

            <meta name="description" content="” />

            <meta name="description" content="” />

            thanks again.

  9. Avatar for mbd24 mbd24 says:

    Thanks For the Script . Usefull script for me .

  10. Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

    You are passing the arguments wrong. Double check the if else statements again.

  11. Avatar for Jacqueline Jacqueline says:

    First of all, thank you for this script! I’ve got some questions:
    Is there any way to set ‘noindex, nofollow’ to the author, category and archive pages with this method?
    And is there a reason why you’re using ‘follow, index’ instead of ‘index, follow’ ?
    Thanks in advance!

    • Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

      Hi Jacqueline,

      The order of index and follow doesn’t matter, it works either way. as for adding noindex nofollow to archive pages, you can modify the code with a simple if else. take a look at the code for the header and it will all make sense.

      Here are the conditional tags in wordpress codex:


      On line 28 you’d start adding your conditions:

      else { if is an archive page and/or …, do this } else {…



      • Avatar for Jacqueline Jacqueline says:

        Thanks Chris for your reply! I added the code in de header, but now there’s a double robots tag.

        Is there a line in the Dreamdare code (in the header) that I should delete?
        Again, thanks in advance!

  12. Avatar for poptropica poptropica says:

    I will try to experiment one of my themes and hope it works. Hope your blog will be updated due to aggressive changes of wordpress. nice job and very helpful.

  13. Avatar for Gayan Gayan says:

    Isn’t that just a html comment (Yoast) which doesn’t have any value? Or is there a catch?

    I was just wondering why you use Ultimate SEO then?

  14. Avatar for Lena Björndahl Lena Björndahl says:

    You are my hero!
    Thank you!

    All I had to do was to remove the ‘<?php' in the beginning of the function code and then it worked! Perfect, nice and clean, exactly how it is suppose to be, thank you again! 🙂

    • Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

      You are welcome 🙂 If you want to re-brand it as your own or if you have clients, just change the “Dreamdare” name to whatever you like and I don’t mind one bit.

  15. Avatar for Rachel Rachel says:

    Just wanted to add, I uploaded this to my sites files and added the code and it works like a charm. Thanks sooooo much. It’s perfect 🙂

  16. Avatar for Rachel Rachel says:

    Thanks for this. And LOL, I will never use anything Yoast creates simply because, as you said, he’s pompous, arrogant and a jerk.

  17. Avatar for funplayz funplayz says:

    I will try this one Chris, if this works with great results i will surely implement it to all my themes. Thank you for sharing. Nice job!

  18. Avatar for Jason Jason says:

    Thanks for the script. I already use custom meta boxes in my theme and adding this was even easier. Is it possible to make the meta description use the post excerpt if the field is left empty? Thank again.

    • Avatar for Chris Sorbi (Admin) Chris Sorbi (Admin) says:

      Hi Jason, you can certainly make the code to pull the excerpt as the meta description but that defeats the whole purpose of it. This plugin is for those who actually want to optimize their content and not rely on machine generated metas. Pulling the excerpt is not going to give you any better result if it wasn’t written for the search engines. Another thing is that you need to trim the excerpt as it is much longer than an average meta description.

Leave a Reply

Your email address will not be published. Required fields are marked *