Hoe create signle page SEO plugin?


For create single line SEO plugin in wordpress website follow these step:
  1. Create new php file and save as rseo.php
  2. Copy this code given below and add it in your rseo.php file
  3. Save file
  4. Convert this file into .zip format
  5. Install from admin
  6. Activate plugins
  7. Thats all

After that you can veiw SEO meta box in your post/pages during create or edit pages

 <?php
/*
Plugin Name: Raghu SEO
Plugin URI: http://www.facebook.com/RaghunathPrasadGurjar
Author: Raghunath Prasad Gurjar | raghunath.0087@gmail.com
Author URI: http://www.facebook.com/RaghunathPrasadGurjar
Description: This is first custom plugin by raghunath on JBI
Version: 1.1
*/

/*  Copyright 2012 raghu  (email : raghunath.0087@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

*/

//Start code for custom gallery

add_action( 'add_meta_boxes', 'add_seo_meta_box' );

/**
 * Adds the SEO meta box to the page screen
 */
function add_seo_meta_box()
{
 global $meta_box;
    add_meta_box($meta_box['id'], $meta_box['title'], 'meta_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
}

//Define SEO Meta box Fields

  $prefix = 'seo_';
    $meta_box = array(
    'id' => 'my-meta-box',
    'title' => 'SEO Information',
    'page' => '',
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
    array(
    'name' => 'Meta Title',
    'desc' => 'enter meta title',
    'id' => $prefix . 'title',
    'type' => 'text',
    'std' => ''
    ),
    array(
    'name' => 'Meta Keyword',
    'desc' => 'enter meta keywords',
    'id' => $prefix . 'keywords',
    'type' => 'text',
    'std' => ''
    ),
    array(
    'name' => 'Meta Description',
    'id' => $prefix . 'description',
    'desc' => 'enter meta description<p align="right">Created by <a href="mailto:raghunath.0087@gmail.com" target="_blank">Raghunath Gurjar</a></p>',
    'type' => 'textarea',
    'std' => ''
    )
    )
    );

//Display SEO Meta Box
function meta_show_box()
{
global $meta_box, $post;
    // Use nonce for verification
    echo '<input type="hidden" name="seo_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
    echo '';
    foreach ($meta_box['fields'] as $field) {
    // get current post meta data
    $meta = get_post_meta($post->ID, $field['id'], true);
    echo '<p>',
    '<label for="', $field['id'], '">', $field['name'], '</label>','';
    switch ($field['type']) {
    case 'text':
    echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />', '<br />', $field['desc'];
    break;
    case 'textarea':
    echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>', '<br />', $field['desc'];
    break;
    '</p>';
    }

    }
}

//Save SEO Meta Box fields Value

add_action( 'save_post', 'save_seo_meta_box' );

function save_seo_meta_box($post_id) {
global $meta_box;
// verify nonce
if (!wp_verify_nonce($_POST['seo_meta_box_nonce'], basename(__FILE__))) {
return $post_id;
}
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
if ('page' == $_POST['post_type'] || 'care_agency' == $_POST['post_type'] || 'post' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($meta_box['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}

//Add Seo Details in header

add_action('wp_head','add_metavalue_header',5);

function add_metavalue_header()
{
global $meta_box, $post;
echo "<!-- Created By Raghunath Gurjar -->";
echo "<meta name='title' content='".get_post_meta($post->ID,'seo_title',true)."'>\n";
echo "<meta name='keywords' content='".get_post_meta($post->ID,'seo_keywords',true)."'>\n";
echo "<meta name='description' content='".get_post_meta($post->ID,'seo_description',true)."'>\n";

}

?>
Advertisements

Sr. Software Engineer

Posted in Wordpress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: