Joel, sometimes @jayroh

menu

Meta descriptions and keywords for each page and post in WordPress

03 Apr 2009

After searching for a plugin that might accommodate this in WordPress and coming up empty, I went digging for a possible easy way to do this with the means available.   Logic dictates that with custom fields this should be rather easy to accomplish.

The only snag might have been that in retreiving a custom field for a page or a post you need the page or post’s ID.   Usually this id is readily available within “the loop”, but what about when we’re up in the tags?    A little searching in the codex reveals that we can grab your pages’ ID with $wp_query->post->ID.  Fantastic – because, with that we’re pretty much done! Adding the following in your theme’s header.php file between … :

” />
” />

.. and “meta_keywords” and “meta_description” as custom fields with your desired content for each will get you to where you want to be.

close
Joel Oliveira

Hi, I'm Joel.

I'm a software engineer in Boston. You can follow me on twitter at @jayroh. I usually tweet about beer, bulldogs, writing code, and sometimes building shubox and thredded.

Articles from 2012

Articles from 2007