Simple wordpress seo plugin using custom meta – Part 1

Meta title, meta keywords and meta description are the first things that everyone will concentrate in the process of SEO. If you are running a wordpress blog, then you may search for wordpress seo plugins to improve your blog’s seo.

In today’s tutorial, we will create a simple wordpress plugin to add unique custom meta data to your blog posts/pages and extend it according to your own needs.

simple wordpress seo plugin

Setup Plugin Information

< ?php
Plugin Name: TutorialsTag Simple seo
Plugin URI:
Description: Simple basic wordpress seo using wordpress custom meta. You can find more information here
Author: KannanC
Version: 1.0
Author URI:

Create Meta box

One of the greatest features of wordpress is Custom fields with which i am going to create the meta data for the blog posts/pages.

First we will create a meta box to hold our input fields.

add_action("admin_init", "seo_meta_box");
function seo_meta_box(){
   add_meta_box("seo-settings", "Simple SEO by TutorialsTag", "seo_settings", "post", "normal", "low");
   add_meta_box("seo-settings", "Simple SEO by TutorialsTag", "seo_settings", "page", "normal", "low");

This will create a meta box in the post editor page. For the second step we need to populate the needed input fields inside the meta box.

Populate the input fields

function seo_settings() {
global $post;
$meta_data = get_post_custom($post->ID); //Retrieve the stored data
wp_nonce_field( 'update_seo_settings', 'seo_settings_nonce' );


< ?php }

Ok, we have the inputs for title, keywords, description, robots and for custom code.

Sometimes you may need to add more meta tags to your header, something like

In that case, we can make use of the custom code field to add our extra header elements.

Now we need to save the input data. We will use update_post_meta to save our data.

Save the data

function save_seo_settings($post_id){
   global $post;
   if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
   return; //to prevent our data from deleting upon auto save 
   if(empty($_POST) || !wp_verify_nonce($_POST['seo_settings_nonce'],'update_seo_settings') )
   return; //wp nonce validation
   $seo_title = trim($_POST["seo_title"]);
   $seo_keywords = trim($_POST["seo_keywords"]);
   $seo_description = trim($_POST["seo_description"]);
   $meta_robot = trim($_POST["meta_robot"]);
   $seo_custom = trim($_POST["seo_custom"]);
   update_post_meta($post->ID, "seo_title", $seo_title);
   update_post_meta($post->ID, "seo_keywords", $seo_keywords);
   update_post_meta($post->ID, "seo_description", $seo_description);
   update_post_meta($post->ID, "meta_robot", $meta_robot);
   update_post_meta($post->ID, "seo_custom", $seo_custom);

You may ask, why we are using DOING_AUTOSAVE contsant here.
If you have the wordpress auto save function enabled and when auto saving, our custom fields data could be deleted. This is because the custom fields will not pass along when auto saving.

So we had successfully written the code to save our meta data for wordpress posts/pages.

In the next part, we will look in to how to create an Options page to have some default settings for this plugin and how to insert our meta data in to the head section.