Ultimate WordPress SEO Meta Tags Without Plugins

Everyone wants to be at the top of page one in the search results for their targeted keywords, it is critical to properly use WordPress SEO meta tags.

If you are using WordPress you already have a very solid, efficient platform to work with because WordPress does a great job of being search engine friendly right out of the box, there is however always room for improvement. A few years ago meta keywords were king, if you stuffed them and your content with enough keywords you could make just about any page rank for just about anything that you wanted, thankfully those days are gone, now content is king BUT there are still a few reasons why having your top of page WordPress SEO Meta Tags setup properly is critical, so plugins like the All In One SEO plugin have become very popular to automate some of the process of generating your WordPress SEO Meta Tags. Plugins like these can do a good job but they do this at a big expense, can be bloated and if not updated properly can be a security problem.

WordPress SEO Meta Tags

WordPress SEO meta tags are not only related to SEO.

They also serve a purpose with many bookmarking sites like Technorati, Delicious, Facebook etc where they will grab your WordPress SEO Meta Tags and description or keywords to use as part of the content that is submitted to their sites, so having these on your pages helps significantly. This post isn’t about debating on the usefulness of WordPress SEO meta tags or why to have them or not as I assume if you are here you already have made that determination for yourself. This post is about WordPress SEO Meta Tags and how to go about getting your WordPress site setup to properly and efficiently be SEO optimized without needing to use some bloated plugin to generate your WordPress SEO Meta Tags that could be a security vulnerability. I am very critical of site efficiency because it has a definitely impact on the overall user experience, so anything that can be done to speed things up and improve the performance of my sites will be something I will definitely look into.

There are a few key WordPress SEO Meta Tags that every site should have, in this post I will only be focusing on the following tags:

  • meta keywords
  • meta descriptions
  • meta robots
  • page title

First off, having keywords and descriptions as part of your WordPress SEO Meta Tags that are specific to your post content is important, so just how do we go about getting those setup to be automatically included in each post page that you publish? We will use the tags for your post as the keywords as they essentially serve the same purpose anyhow and we will use a portion of the excerpt as the description. In order to do this we need to setup a few functions in your themes functions.php file which will be located inside your template folder, if you don’t have a functions.php file in there already simply create one and we will add the following pieces of code to it and you will have very effecient WordPress SEO Meta Tags for your site.

This first piece of code grabs the tags for your post from the database and then returns them in an array that we can use to display them as a simple comma separated list in the keyword meta tag section of your WordPress SEO Meta Tags. The part at the end uses the is_home code to use your sites default keywords on the homepage.

[php]//csv tags for meta keywords by admindaily.com
function tags4meta() {
$posttags = get_the_tags();
foreach((array)$posttags as $tag) {
$tags4meta .= $tag->name . ‘,’;
if (!is_single()) { ?>add,your,homepage,keywords,that,you,want,in here,like so<?php }
echo "$tags4meta";


This second piece of code will generate a custom excerpt that we can control the length of, I presently use this for my WordPress featured post slider on my home page as well as for my post meta descriptions. I will show you how to alter the returned length once we get to editing the template files, so for now just paste the following into your functions.php file as you did with the last one and this will conclude the edits to that file so you can save/upload it after you add in the following code.

[php]//Custom excerpt for featured posts and meta descriptions by admindaily.com
function the_content_limit($max_char, $more_link_text = ‘(more…)’, $stripteaser = 0, $more_file = ”) {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]&gt;’, $content);
$content = strip_tags($content);

if (strlen($_GET[‘p’]) > 0) {
echo $content;
else if ((strlen($content)>$max_char) && ($space = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $space);
$content = $content;
echo $content;
else {
echo $content;

Now we can move onto editing the theme template files, the only file left to edit is your header.php which we will modify to properly display your page title in the format that search engines can make the best use of, we will setup the meta keywords to display the results of the function we created earlier, we will insert the code to properly setup the meta description portion of the WordPress SEO Meta Tags and lastly we will put in the code for the robots meta tag to prevent duplicate content from being indexed and to properly guide the search engines to the content we want indexed and let them know what we prefer they ignore. Again, all of these edits will be in the <head> section of the file as well.

The code for the title tag is pretty straight forward part of setting up your WordPress SEO Meta Tags, on your home page it will display your site name as configured in your admin settings page followed by a | then the text at the tail end that you will want to customize to suit your tastes, just make sure the formatting of the code stays the same and that you keep the ‘ (single quotes) around the code as they are in this example. On all other pages, posts etc it will show the title if the format of Page/Post Title here | Site Name Here which puts your keyword rich post or page title at the front of the title where it should be as those words are much more important to the search engines than your site name is. If you want to see an example of this in use, just check out the WordPress SEO Meta Tags on this very site.

[php]<title><?php wp_title(”); ?><?php if(wp_title(”, false)) { echo ‘ | ‘; } ?><?php bloginfo(‘name’); if(is_home()) { echo ‘ | Your Short Catch Phrase Here’ ; } ?></title>[/php]

Next we will include the code that will handle the meta keywords part of your WordPress SEO Meta Tags for all pages, remember that we configured what keywords to show on the home page in the functions.php file so we dont need any logic included here, just a simple line of code that will display the desired results for our pages automatically.

[php]<meta name="keywords" content="<?php echo tags4meta(); ?>" />[/php]

The next piece of code to add will generate the meta description portion of your WordPress SEO Meta Tags which as stated earlier uses a modified version of our post excerpt which we can control the length of in this piece of code by changing the number of characters displayed at the end of the code where you see <?php the_content_limit(200)?>, I generally use 160-200 as it seems to work well for bookmarking sites but you can of course set this to whatever your preference is. This code will show our modified excerpt as the meta description for single posts as well as pages that you have on your WordPress site as long as there is content to display, if the post/page is blank or if it is your home page, this code will simply use your sites description as configured in your admin settings page. I personally prefer to not include this on archive pages etc as doing so would have many pages with identical meta descriptions and we will be telling the search engines not to index those pages anyhow with our robots meta tags in the next step.

[php]<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php the_content_limit(200)?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo(‘description’); ?>" />
<?php endif; ?>[/php]

The last bit of code is to tell the search engines what pages we want them to index, what pages we want them to follow links on etc. It is my personal preference to only have my home page, single posts and pages indexed as everything else is duplicate content and doesn’t add anything to the overall user experience on my site. I do have it configured to still follow all links on all pages so everything can be used to discover content, but only the pages I want will be indexed. As an example, if you are searching for “Ultimate WordPress SEO Meta Tags Without Plugins“, I would prefer you find this post directly instead of a category archive page containing a link to this post, you can change it to fit your needs if you wish. Again, simply insert the following code into the <head> section, save or upload and you will be good to go, you can of course change the content to suit your specific needs.

[php]<?php if(is_single() || is_page() || is_home()) { ?>
<meta name="robots" content="noodp" />
<?php } else { ?>
<meta name="robots" content="noindex,follow" />
<?php }?>[/php]

After doing these few modifications you will be set for WordPress SEO meta tags, all without using any bloated or potentially insecure plugins that use too many resources and can slow down your site.

Site optimization should always put the overall user experience as your top priority, by cleaning up your site, optimizing your code and limiting the number of plugins that you use, your WordPress site can be fast and search engine friendly at the same time. If you have any questions about WordPress SEO meta tags please feel free to post them here.

7 thoughts on “Ultimate WordPress SEO Meta Tags Without Plugins”

  1. Thanks for the great tips, I have tried every plugin made for this and never realized I could do it all like this. Great post

  2. Great explanation about how to embed the necessary PHP code to generate the Meta tags and titles. The only problem is that sometimes its better to provide a different and more SEO title on the browser than just using the article title itself. Same with the Meta Description where the first couple of sentences may not be as good as a custom description designed to attract user clicks. Is there a way maybe to do this with a custom field? I would like to avoid the bloated plug-in as well because it does slow down the site quite a bit.

    • You are correct, some times it is better to use something more specific. In my case I just make sure that my first paragraph is setup how I would want my description which helps on page SEO as well.. If you wanted to use a custom field you certainly could do so, you would just replace the areas you want to use custom fields for with something along the lines of ID, 'your_custom_field_name',true) ?>

  3. I used this and it worked out fine. for me, i was concerned about the title as well. The way it turned out, was I already a had an effective title setup, and added this to it (the head) without an issue. I am hoping this will turn into an effective SEO update for my site. Staying on topic, I will not mention the other major action I am working on I believe will affect SERP here.

    This is a good move for adding descriptions, and keywords, and conditionally dealing with your site’s main page (is_home), the clicked post (is_single), and pages (is_page). I looked for something (a similar function) related to links but did not find anything. For me that would have made this solution a home run.

    I appreciated this a whole lot though.


Comments are closed.