How to use custom fields in WordPress to display unique content in your post

A client of mine requested for a feature to control a section of the post. He was basically an SEO and he wanted his posts to look unique to search engines so that they get better rankings on them. As you know the more traffic you get the more visible you are on the internet.

I went about my work. I had read about Custom Fields on WordPress and I believed that they provided the answer to my problem. Custom Fields allow you to create fields which you can then use anywhere on your post page.

I created a field by the name of topcontent. I input some value against it and saved it with the post. I then browsed to the post page. I did not see the custom field and its value yet as obviously I had not fetched it and displayed it on the page.

I opened the header.php file in the theme directory. I entered the following code

$custom_fields = get_post_custom($post->ID);
$my_custom_field = $custom_fields['topcontent'];
$display_title = $my_custom_field[0];
echo $display_title;

where get_post_custom retrieves all the custom values associated with the post which I am referencing with the $post->ID.

I saved and uploaded the file and the custom field value started to display on the page.
I made the required number of custom fields for the client which he was able to change the value for each post thereby allowing him to display unique content to the search engines.

Hope the above helped.

Leave a Reply

Your email address will not be published. Required fields are marked *