Set Metadata in the WordPress Manually

Discussion Board : Create metadata tag in the WordPress manually with Add Custom Field features.
Requirements : WordPress bundle, already installed, because this tutorial we will practice in our local website (or for those of you who have hosting with wordpress cms, can be practicing in your hosting)

If you have to scroll down the page your WordPress post, you will find the menu “Add custom field”, with a brief description follows:

Custom fields can be used to add extra metadata to a post that you can use in your theme.

Before we discuss much about how to tag metadata, in fact, whether these metadata tags?

metadata tags are html tags that are at the head area in a page html page . tags are metadata that is useful in general is description , or keywords , which explains about a site, because the common definition of metadata is “data about data “. Metadata is commonly used by search engines such as Google or Yahoo to index your site pages.

When we do a post on WordPress, the metadata tags will not be found on our web page. Why? Because the metadata is actually determined by the author (the author of the article, simply because the author is most knowledgeable about what he wrote in the article, so only the author of the most appropriate in describing the keyword or description about the page.) WordPress can not read the mind of a author. One way to provide metadata tags in WordPress is done with Add Custom Field .

Ok, How do I? For this case study, we will try to create metadata for keywords .

1. Login in your wordpress.
2. Go to the Post – Add New Post pages.
3. Scroll down till you find the Custom Field menu.
4. Choose “Add Custom Field.”button. Type “keywords” on the name, and fill “wordpress, metadata, seo” in the value (this value is just a sample, the mean is the keywords for the articles that was writen.)

5. Click Add Custom Field to save.
6. For the next post, you do not need to create a Custom Field again if you want to use metadata tag keywords, you just choose to using the last field you have created, like the picture below.

After you successfully add custom fields in WordPress, just how We see the metadata tags that have been created on our themes. Time for The trick.

1. Find a file called functions.php which is located in your WordPress root directory (wp-content>> themes>> name of your themes>> functions.php). Add this script below in the functions.php file.

[sourcecode language=”php”]
function set_keywords(){
global $post;
$keywords = get_post_meta($post->ID, ‘keywords’, true);
$default_keywords = ‘keywords, default, up, to, you’;
$metatag= "";

if (empty($keywords)){
$keywords = $default_keywords;
if (is_home() || is_front_page()){
$keywords = $default_keywords;

$metatag.= "<meta name=\"keywords\" content=\" ";
$metatag.= $keywords;
$metatag.= "\" />";
$metatag.= "\n\n";

echo $metatag;
add_action(‘wp_head’, ‘set_keywords’);

Happy WordPress-ing ! 😀