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.
  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. Assasin posted the following on May 1, 2009 at 4:57 am.

    Hi! this is great, thanks.

    Reply to Assasin
  4. Dudelka posted the following on June 27, 2009 at 7:31 am.

    Good plug-in, thanks

    Reply to Dudelka
  5. Неприврун 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 Неприврун
  6. Kaxii posted the following on September 25, 2010 at 8:02 pm.

    Well its a good idea to hide duplicate content but I prefer to post new content and get it indexed so the search engines rank me better.
    Cheers

    Reply to Kaxii
  7. Manoj Bhatt posted the following on December 17, 2011 at 9:13 am.

    This is best one article so far I have read online. I would like to appreciate you for
    making it very simple and easy. I have found another nice post related to this post over
    the internet which also explained very well. For more details you may check it by visiting this url…

    http://mindstick.com/Articles/a70d80fd-c9c8-4d51-864b-39c3b1c9ba31/?Meta%20Tags%20in%20WordPress

    Thanks

    Reply to Manoj Bhatt

Leave a reply

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