Subscribe and/or follow
Recent Entries
- My new Mac Mini
- Guest Post: How To Display Ad Blocks In Specific Posts In WordPress
- USB Sound Blaster Live! 24-bit on Windows 7
- Google has ajaxed their search engine
- Opera 10 equal to FireFox 3 or even better ?
- Save your code snippets with Snippely
- Re-inserting ads on the blog and using a free theme
- Always-on-top solution for Windows OS
- Bots following me on Twitter ?
- Best way to inspect dead links using your 404 page
Popular Entries
- phpbb3 should have native support for quick edit and quick reply
- Latest posts standalone script for phpbb3 and phpbb2
- Integrate RSS and ATOM into a phpbb3 based forum
- Top 10 phpbb3 styles
- Integrate AdSense into phpbb3
- Remove ads from Yahoo! Messenger 9
- K2 RC6 is now available and compatible with WP 2.5
- Google's PageRank Update outcome
- RSS awareness day
- Care to read some reviews about web hosting ?
WordPress SEO – optimize your META Keywords & Description manually
I am a big fan of the “All In One SEO Pack” plugin for WordPress. It really helps you make sure your blog is as robot-friendly as it gets. I’m not going to give any details because this post is not about the AIOSP plugin. I’m loving the idea of having such great plugins helping you with what could easily get a really messy task. On the other hand I like to help out myself and write small pieces of code that give me exactly the results I want without having all sort of third-party plugins doing it for me.
What I will try to do is to have 100% dynamical META keywords and descriptions for every page of the blog without using any plugins.
Let’s take a look inside the header.php file of your theme for instance. You should see the lines below somewhere in your file however bare in mind that depending on your theme the following lines might be slightly different:
Before going any further I should make something clear: the keywords attribute should be relevant to the content of the page. That’s a must and everyone knows why. So before defining some static keywords blog-wide (I suggest that 8 should be the maximum number of keywords used) in the header.php file that basically define the area covered by your blog (sports, traveling, etc.) you might want to consider the fact that these keywords will be used for all your posts and pages.
A common form for the description attribute is the following:
description which you can easily define in the admin interface. Well, that again doesn’t serve you any good as the description of your blog might not accurately summarize a certain post (probably none of them).
OK so now we have some static keywords and a general description. Both of them are carried around on your entire blog without actually having something to do with a random particular page. Keywords and description that don’t match the content of the page ? I don’t think anyone wants that. That’s about it with the static keywords and description; problem which I’ve seen on many blogs.
As we move further I will concentrate more on the keywords attribute and leave the description at the end. I for example have three methods for defining the tags for an article:
Of course depending on which plugins you have installed you might have other possibilities of defining tags for a post.
Instead of using some complicated methods to achieve this simple task why not use the already built-in form. You can then call the the_tags() function and have the post’s tags shown right under its content. Of course that’s nothing new, everyone is doing it since like forever. OK so why not using those tags as keywords ? Yesterday it sounded like a good idea for me so I said to myself why not try to put those tags as keywords in the header.php file of my theme. What will we accomplish with this ? Well… nothing much actually except for the fact that all the META keywords will perfectly match the content of any page of my blog.
Enough with this already, let me give you the code that does all the magic.
" />Due to a tricky set of instructions in GeSHi I had to split the code into those three blocks above. The line numbering however is correct so you should assemble the code easily.
Now that you copied the code above into your header.php file you will see that your articles aren’t showing up on their pages. Why is that ? Because you didn’t call the_post() function in a proper loop. Actually there’s no loop at all there. The actual loop used for displaying the post’s content is in your single.php file. Now we have to undo all the “damage” we caused. Don’t worry, nothing bad happened. All you need to do is to place the following code before your loop (if you don’t know what the loop is, here’s an explanation):
There you go ! Now everything should be working again.
This might not be a viable solution for some of you out there but for me it definitely does the trick. I’m sure that some of you who are advanced PHP programmers will find or already know a simpler method for what I’ve accomplished here. Hopefully the commented lines will help you understand the code and not get in your way while trying to understand it.
As I promised I will now offer a variant of generating the description attribute entirely dynamic, again strictly based on the post page. I thought that a good description would be an actual excerpt of the article. It’s more like a preview after all. The default excerpt (if you don’t write a specific one in the Excerpt box under the WYSIWYG editor) contains the first 55 words of your article. No HTML tags, no nothing, just plain text (well, not actually). So what I’ve accomplished is to have a specific, unique description, again for each and every page of my blog. Here is the code:
Again, be advised of the code splitting I had to do. Because we called the_post() function in the keywords attribute (which in this case has to be before the description attribute) we don’t need to apply “the fix” again in the single.php file. However if you want to try only the code that affects the description then you will need to call the_post() function right after is_single() function, exactly as shown in the code related to keywords attribute.
Some would say that this whole thing isn’t such a big deal but actually it’s just one idea I had yesterday which I am blogging today. The possibilities are endless. We are limited only by our knowledge and imagination. Please feel free to comment on this idea of mine. You might have something to say that really matters. And as a wrap up, I really hope you enjoyed reading this article and hopefully it will help you in a way or another.