目前正在使用下面的代码进行SEO。如果将下面的代码添加到标题中效果很好,那么您必须手动创建查询的字段。大多数客户端几乎无法绕过WordPress UI,更不用说创建字段了。我试图编写一个插件,使每个页面上的字段在默认情况下都可见,以便客户端只需输入值。谢谢
<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; ?>