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


Leave a reply

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