Monday 05 December, 2011 at 11:38 pm / 0 comments
Using Custom Fields To Generate Meta Tag Info In WordPress
Ever thought about using a custom field to dynamically generate meta tag information for your WordPress blog? Took me a couple of hours of googling and experimenting before I figured out how to do it, so I figured I’d post the solution.
My first guess was this:
<meta name="description" content="<?php echo get_post_meta($post->ID, 'CustomFieldName', true); ?>" />And I was wrong. Turns out you need to use get_the_id() instead of $post->ID.
<meta name="description" content="<?php echo get_post_meta(get_the_id(), 'CustomFieldName', true); ?>" />
Leave a Reply
Your email address will not be published. Please fill the required fields...