Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently using the code below for SEO. When the Code Below if added to the header works perfectly but then you have to manually create the fields that are queried. Most Clients hardly get around the WordPress UI let alone create a field. I trying to write a plugin that can make the fields visible on every page edit by default so that the client would just put the value. Thanks

<title>

<?php if ( is_single() || is_page() ) { ?><?php $title = get_post_meta($post->ID, 'Title', true);  if ($title) { ?>
<?php echo $title; ?> | <?php bloginfo('name'); ?>
<?php } else { ?>
<?php wp_title(''); ?> | <?php bloginfo('name'); ?>
<?php } ?>
<?php } ?>

</title>

<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php $description = get_post_meta($post->ID, 'Description', true);  if ($description) { ?><?php echo get_post_meta($post->ID, "Description", true); ?>
<?php } else { ?><?php the_excerpt_rss(); ?><?php } ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>

<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="keywords" content="<?php $keywords = get_post_meta($post->ID, 'keywords', true);  if ($keywords) { ?><?php echo get_post_meta($post->ID, "keywords", true); ?>
<?php } else { ?><?php the_excerpt_rss(); ?><?php } ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="keywords" content="<?php bloginfo('keywords'); ?>" />

<?php endif; ?>

Plugin structure

<?php
/*
Plugin Name: WP Site GPS
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: Non Complicated Search Engine Optimization plugin
Version: 001
Author: Chibueze Okechukwu
*/



function mySEO() {
    include ('wp-site-gps-transport.php');
}


// Add hook for admin <head></head>
add_action('admin_head', 'mySEO');
// Add hook for front-end <head></head>
add_action('wp_head', 'mySEO');

?>

Plugin Include File

<title>

<?php if ( is_single() || is_page() ) { ?><?php $title = get_post_meta($post->ID, 'Title', true);  if ($title) { ?>
<?php echo $title; ?> | <?php bloginfo('name'); ?>
<?php } else { ?>
<?php wp_title(''); ?> | <?php bloginfo('name'); ?>
<?php } ?>
<?php } ?>

</title>

<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php $description = get_post_meta($post->ID, 'Description', true);  if ($description) { ?><?php echo get_post_meta($post->ID, "Description", true); ?>
<?php } else { ?><?php the_excerpt_rss(); ?><?php } ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>

<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="keywords" content="<?php $keywords = get_post_meta($post->ID, 'keywords', true);  if ($keywords) { ?><?php echo get_post_meta($post->ID, "keywords", true); ?>
<?php } else { ?><?php the_excerpt_rss(); ?><?php } ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="keywords" content="<?php bloginfo('keywords'); ?>" />

<?php endif; ?>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Typically what plugin authors will do is use add_meta_box to add an area on the post edit screen for users to enter extra data. Within the functions that save and retrieve the data to generate your meta box, use the post meta functions to store it. Remember that prefixing a meta key with an underscore will keep things tidy by hiding the key from the normal custom fields UI.

share|improve this answer
    
Thanks alot, That helped. –  Dz.slick Dec 22 '12 at 6:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.