Wordpress Meta Tag/SEO plugin

Posted on Wednesday the 7th of March, 2007 at 2:09 pm in Plugins

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.

  1. <?php
  2. /* 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/ */
  3. add_action('wp_head', 'seo_head');
  4. add_action('wp_head', 'seo_permalink');
  5. function seo_head() {
  6. if((is_home() && ($paged <2 )) || is_single() || is_page()) {
  7. $meta = '<meta name="ROBOTS" content="index,follow"/>';
  8. } else {
  9. $meta = '<meta name="ROBOTS" content="noindex,follow"/>';
  10. }
  11. echo $meta;
  12. echo '
  13. <meta http-equiv="Pragma" content="no-cache" />
  14. <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
  15. <meta http-equiv="Expires" content="-1" />
  16. <meta name="copyright" content="© 2005 - 2007 - Anthology of Ideas" />
  17. ';
  18. echo '<meta name="description" content="';
  19. if ( is_404() ) {
  20. echo '404, Page Not Found. Sorry, but the page you requested cannot be found';
  21. }elseif ( is_search() ) {
  22. echo 'Search Results for '.$search;
  23. }elseif ( is_archive() ) {
  24. echo ucfirst(strip_tags(single_cat_title())).' from Anthology of Ideas.';
  25. }elseif((is_page() || is_single()) && !is_tag()){
  26. echo seo_excerpt();
  27. }else{
  28. echo bloginfo('description');
  29. }
  30. echo '" />';
  31. echo '
  32. <meta name="name" content="';
  33. bloginfo('description');
  34. echo '" />
  35. <meta name="rating" content="general" />
  36. <meta name="expires" content="never" />
  37. <meta name="distribution" content="global" />
  38. <meta name="revisit-after" content="15 days" />';
  39. }
  40. function seo_permalink() {
  41. global $withcomments,$post,$wp_query;
  42. $cur_url = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  43. if(is_single()){
  44. $permalink = get_permalink($post->ID);
  45. }elseif(is_page()){
  46. $permalink = get_page_link($post->ID);
  47. }elseif(is_category()){
  48. $cat = $wp_query->get_queried_object();
  49. $permalink = str_replace('./','',get_category_link($cat->cat_ID));
  50. }
  51. if (!$permalink)
  52. return;
  53. if ($permalink != $cur_url) {
  54. header('HTTP/1.1 301 Moved Permanently');
  55. header('Status: 301 Moved Permanently');
  56. header("Location: $permalink");
  57. exit(0);
  58. }
  59. }
  60. function seo_excerpt($word_limit=40){
  61. global $post;
  62. if ( !empty($post->post_password) ) { // if there's a password
  63. return false;
  64. }
  65. // decide on the content
  66. if ($post->post_excerpt != ''){
  67. $output = $post->post_excerpt;
  68. }else{
  69. $content = $post->post_content;
  70. $content = strip_tags($content);
  71. //$content = str_replace(array(chr(13),"\n","\r", ' ' ), ' ', $content);
  72. $content = preg_replace('/\s+/',' ',trim($content));
  73. $words = explode(' ', $content, $word_limit + 1);
  74. if (count($words) > $word_limit) {
  75. array_pop($words);
  76. array_push($words, '...');
  77. $output = implode(' ', $words);
  78. }else{
  79. $output = $content;
  80. }
  81. }
  82. //$output = apply_filters('the_excerpt', $output);
  83. if(strpos($output,'UTW_')==true){$output = '';}
  84. return $output;
  85. }
  86. ?>
  87. Use the following to copy and paste the code.

Related posts

  1. Faraz posted the following on September 16, 2008 at 1:28 pm.

    Why aren’t there options for actual plugins?

    Reply to Faraz
    1. Aaron posted the following on September 16, 2008 at 1:30 pm.

      Because this was just a script I wrote for myself that I posted in case someone else needed it.

      Reply to Aaron
  2. rob posted the following on November 12, 2008 at 10:09 am.

    this is great, thanks.

    Reply to rob
  3. Kenneth Lee posted the following on February 24, 2009 at 6:54 am.

    Thanks for the plugin bro. It is very useful.

    Reply to Kenneth Lee
  4. Wordpress Meta Tag/SEO plugin posted the following on February 26, 2009 at 2:55 am.

    <blockquot

    e>

    Reply to Wordpress Meta Tag/SEO plugin
  5. seo company uk posted the following on March 11, 2009 at 1:29 pm.

    Hey, Thanks for this useful article. Keep it up. :)

    Reply to seo company uk
  6. Assasin posted the following on May 1, 2009 at 4:57 am.

    Hi! this is great, thanks.

    Reply to Assasin
  7. Memphis SEO posted the following on May 6, 2009 at 10:12 am.

    Thank u for the 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).

    Reply to Memphis SEO
  8. education posted the following on June 10, 2009 at 11:28 pm.

    :D :D :D

    thankks

    about your article

    Reply to education
  9. rohit.sirohiya posted the following on June 24, 2009 at 6:51 am.

    Hello All visitors by means off Shubhinetwork, we provide you an opportunity of online job,off add a posting which you can do sitting at your homes it self & also free off cost. So ShubhiNetwork Welcome Peoples from Any part of the world to come and join their hand with it. Sign up Free 100ore information visit below this site
    ———–
    roxyrohit

    ————-
    SEOSEO

    Reply to rohit.sirohiya
  10. Dudelka posted the following on June 27, 2009 at 7:31 am.

    Good plug-in, thanks

    Reply to Dudelka
  11. navjeet posted the following on July 17, 2009 at 6:34 am.

    Affordable Search engine optimization(SEO) Service from an Online Internet marketing company. outsource Seo services to India Seo company India. Seo Company Seo Services India from a professional SEO India.

    Reply to navjeet
  12. Stephan posted the following on July 21, 2009 at 10:01 pm.

    Why arenâ??t there options for actual plugins???

    Reply to Stephan
  13. seo arvin posted the following on July 29, 2009 at 3:53 pm.

    Great article on SEO.

    Reply to seo arvin
  14. AsterHost posted the following on August 9, 2009 at 3:27 am.

    Useful script.
    Thank You

    Reply to AsterHost
  15. nantong seo posted the following on August 24, 2009 at 11:55 pm.

    :D very good

    Reply to nantong seo
  16. seo jaipur posted the following on August 26, 2009 at 2:22 am.

    I hit a link in google and read
    a blog on this site about the economic
    strain we are taking in SA. I tried to
    find it once I registered, unfortunately
    to no avail. Perhaps somebody could be
    so kind as to show me the way? Anyway,
    I’m here and waiting!
    ————–
    Rockstarbabu
    —————-

    Reply to seo jaipur
  17. Ðеприврун posted the following on November 8, 2009 at 12:11 pm.

    oh, mate, it’s really useful, especially for my stupid russian hoster and its server

    Reply to Ðеприврун
  18. seo expert India posted the following on December 16, 2009 at 1:55 am.

    Our Web & SEO consultants are experienced and qualified enough to fulfill your demands for complete web & SEO services in India.

    Reply to seo expert India
  19. Manchester UK based Seo company posted the following on January 8, 2010 at 5:41 pm.

    Thank u for the plugin that prevents duplicate content from being indexed by Google.
    It is surely a good post giving information about avoiding duplication content from being indexed by Google. I am just wondering how people who are not that knowledgeable in programming can use this.

    Reply to Manchester UK based Seo company
  20. sonia posted the following on February 28, 2010 at 10:25 am.

    I was searchign this plugin,thanks for sharing here, Iam thankful to you..

    Reply to sonia
  21. seo posted the following on March 19, 2010 at 10:24 pm.

    Our Web & SEO consultants are experienced and qualified enough to fulfill your demands for complete web & SEO services in India.

    Reply to seo
  22. Desi Girls posted the following on June 20, 2010 at 4:04 am.

    I was searchign this plugin,thanks for sharing here, Iam thankful to you..

    Reply to Desi Girls

Leave a reply

:) :D :( :o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: ;) :!: :?: :idea: :arrow: :| :mrgreen: