WordPress Meta Tag/SEO plugin

April 7, 2007 by aaron

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(&#039;wp_head&#039;, &#039;seo_head&#039;);
add_action(&#039;wp_head&#039;, &#039;seo_permalink&#039;);
function seo_head() {
    if((is_home() && ($paged < 2 )) || is_single() || is_page()) {
        $meta = &#039;<meta name="ROBOTS" content="index,follow"/>&#039;;
    } else {
        $meta =  &#039;<meta name="ROBOTS" content="noindex,follow"/>&#039;;
    }

    echo $meta;

echo &#039;
<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="&copy; 2005 - 2007 - Anthology of Ideas" />
&#039;;


echo &#039;<meta name="description" content="&#039;;

if ( is_404() ) {
echo &#039;404, Page Not Found. Sorry, but the page you requested cannot be found&#039;;
}elseif ( is_search() ) {
echo &#039;Search Results for &#039;.$search;


}elseif ( is_archive() ) {
echo ucfirst(strip_tags(single_cat_title())).&#039; from Anthology of Ideas.&#039;;

}elseif((is_page() || is_single()) && !is_tag()){
echo seo_excerpt();

}else{
echo bloginfo(&#039;description&#039;);

}
echo &#039;" />&#039;;




echo &#039;
<meta name="name" content="&#039;;
bloginfo(&#039;description&#039;);
echo &#039;" />
<meta name="rating" content="general" />
<meta name="expires" content="never" />
<meta name="distribution" content="global" />
<meta name="revisit-after" content="15 days" />&#039;;

}


    function seo_permalink() {
        global $withcomments,$post,$wp_query;
  $cur_url = &#039;http://&#039;.$_SERVER[&#039;HTTP_HOST&#039;] . $_SERVER[&#039;REQUEST_URI&#039;];
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(&#039;./&#039;,&#039;&#039;,get_category_link($cat->cat_ID));
}


        if (!$permalink)
            return;
        if ($permalink != $cur_url) {
            header(&#039;HTTP/1.1 301 Moved Permanently&#039;);
            header(&#039;Status: 301 Moved Permanently&#039;);
            header("Location: $permalink");
            exit(0);
        }
    }

function seo_excerpt($word_limit=40){
    global  $post;
    if ( !empty($post->post_password) ) { // if there&#039;s a password
        return false;
    }

// decide on the content
    if ($post->post_excerpt != &#039;&#039;){
        $output = $post->post_excerpt;
    }else{
        $content = $post->post_content;

$content = strip_tags($content);
//$content = str_replace(array(chr(13),"\n","\r", &#039;  &#039; ), &#039; &#039;, $content);
        $content = preg_replace(&#039;/\s+/&#039;,&#039; &#039;,trim($content));
            $words = explode(&#039; &#039;, $content, $word_limit + 1);

            if (count($words) > $word_limit) {
                array_pop($words);
                array_push($words, &#039;...&#039;);
                $output = implode(&#039; &#039;, $words);
            }else{
            $output = $content;
            }

    }

    //$output = apply_filters(&#039;the_excerpt&#039;, $output);
if(strpos($output,&#039;UTW_&#039;)==true){$output = &#039;&#039;;}
return $output;


}
?>
Categorized as:
comments powered by Disqus