WordPress Meta Tag/SEO plugin
I was sick of having a half dozen different plugins to add meta tags and fix the robots, so I wrote a plugin that prevents duplicate content from being indexed by Google, adds useful meta tags, and ensures that all posts are at one single permalink (using 301 redirects of course). This is more a shell of a plugin than an actual plugin as there are no options, and there are obvious flaws such as it doesn’t allow you to use paged posts. If you want to make changes you will have to do it yourself.
Copy the following into a php file. Upload it. If you need any more instructions than that, you are better off using a plugin that is a little more user friendly because using this plugin incorrectly can kill your site.
<?php
/*
Plugin Name: Ultimate SEO
Plugin URI: http://anthologyoi.com/
Description: This plugin combines the functionality of other SEO plugins.
Author: Aaron Harun
Version: 0.0
Author URI: http://anthologyoi.com/
*/
add_action('wp_head', 'seo_head');
add_action('wp_head', 'seo_permalink');
function seo_head() {
if((is_home() && ($paged < 2 )) || is_single() || is_page()) {
$meta = '<meta name="ROBOTS" content="index,follow"/>';
} else {
$meta = '<meta name="ROBOTS" content="noindex,follow"/>';
}
echo $meta;
echo '
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Expires" content="-1" />
<meta name="copyright" content="© 2005 - 2007 - Anthology of Ideas" />
';
echo '<meta name="description" content="';
if ( is_404() ) {
echo '404, Page Not Found. Sorry, but the page you requested cannot be found';
}elseif ( is_search() ) {
echo 'Search Results for '.$search;
}elseif ( is_archive() ) {
echo ucfirst(strip_tags(single_cat_title())).' from Anthology of Ideas.';
}elseif((is_page() || is_single()) && !is_tag()){
echo seo_excerpt();
}else{
echo bloginfo('description');
}
echo '" />';
echo '
<meta name="name" content="';
bloginfo('description');
echo '" />
<meta name="rating" content="general" />
<meta name="expires" content="never" />
<meta name="distribution" content="global" />
<meta name="revisit-after" content="15 days" />';
}
function seo_permalink() {
global $withcomments,$post,$wp_query;
$cur_url = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if(is_single()){
$permalink = get_permalink($post->ID);
}elseif(is_page()){
$permalink = get_page_link($post->ID);
}elseif(is_category()){
$cat = $wp_query->get_queried_object();
$permalink = str_replace('./','',get_category_link($cat->cat_ID));
}
if (!$permalink)
return;
if ($permalink != $cur_url) {
header('HTTP/1.1 301 Moved Permanently');
header('Status: 301 Moved Permanently');
header("Location: $permalink");
exit(0);
}
}
function seo_excerpt($word_limit=40){
global $post;
if ( !empty($post->post_password) ) { // if there's a password
return false;
}
// decide on the content
if ($post->post_excerpt != ''){
$output = $post->post_excerpt;
}else{
$content = $post->post_content;
$content = strip_tags($content);
//$content = str_replace(array(chr(13),"\n","\r", ' ' ), ' ', $content);
$content = preg_replace('/\s+/',' ',trim($content));
$words = explode(' ', $content, $word_limit + 1);
if (count($words) > $word_limit) {
array_pop($words);
array_push($words, '...');
$output = implode(' ', $words);
}else{
$output = $content;
}
}
//$output = apply_filters('the_excerpt', $output);
if(strpos($output,'UTW_')==true){$output = '';}
return $output;
}
?>