Using Custom Fields To Generate Meta Tag Info In WordPress
Category: Coding
0
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:
|
1 2 |
<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.
|
1 2 |
<meta name="description" content="<?php echo get_post_meta(get_the_id(), 'CustomFieldName', true); ?>" /> |

This post is missing your voice. Leave a comment.