jasonbeack


SUBMITTED BY: jasonbeack

DATE: Aug. 31, 2017, 9:58 p.m.

UPDATED: Nov. 5, 2017, 8:16 p.m.

FORMAT: PHP

SIZE: 8.6 kB

HITS: 10324

  1. <a target="_blank" href="http://www.bitcoclix.com/?ref=earnbtcptc"><img src="http://www.bitcoclix.com/banner2.gif" border="0" width="728" height="90" /></a>
  2. https://www.raisepoints.com/?r=earnmoneyptc
  3. http://btcclicks.com/?r=114cfc23
  4. <a target="_blank" href="http://fingersclix.com/?ref=earnmoneyptc"><img src="https://fingersclix.com/banner1.gif" border="0" width="468" height="60" /></a>
  5. <a target="_blank" href="https://www.uniclique.net/?ref=earnmoneyptc"><img src="http://www.uniclique.net/images/banner1.gif" border="0" width="468" height="60" /></a>
  6. <?php
  7. /*
  8. Plugin Name: Auto Keywords and Description Generator
  9. Plugin URI: http://michael.chanceyjr.com/free-stuff/auto-keywords-and-description-generator/
  10. Description: Auto create Keywords and description meta tags from blog post information
  11. Version: 1.3.2
  12. Author: Michael E. Chancey Jr.
  13. Author URI: http://michael.chanceyjr.com
  14. */
  15. function generateMetaTags()
  16. {
  17. global $post;
  18. $author = get_userdata($post->post_author)->display_name;
  19. $keywords = "";
  20. $description = "";
  21. //DETERMINE WHERE TO LOAD THE INFORMATION FROM
  22. if(is_home() || is_front_page())
  23. {
  24. //LOAD KEYWORDS FROM USER SPECIFIED STRING
  25. $keywords = get_option("metakeywords");
  26. //LOAD DESCRIPTION FROM BLOGINFO
  27. $description = get_option("metadescription");
  28. }
  29. elseif(is_page() && !is_home() && !is_front_page())
  30. {
  31. //PULL THE VALUES FROM THE SAVED SETTINGS IN THE DATABASE
  32. $tmpPage = get_page(get_the_ID());
  33. $keywords = get_option($tmpPage->ID . "_keywords");
  34. $description = get_option($tmpPage->ID . "_description");
  35. }
  36. elseif(is_single())
  37. {
  38. //LOAD POST TITLE AS DESCRIPTION
  39. $description = $post->post_title;
  40. //BUILD LIST OF KEYWORDS FROM TAGS
  41. $tags = wp_get_post_tags($post->ID);
  42. foreach($tags as $tag)
  43. {
  44. //ONLY ADD THE COMMA IF THERE ARE OTHER KEYWORDS IN FRONT OF THIS ONE
  45. if($keywords != "" && $keywords != NULL)
  46. $keywords = $keywords . ", ";
  47. //APPEND THE TAG AS A KEYWORD
  48. $keywords = $keywords . $tag->name;
  49. }
  50. }
  51. elseif(is_category())
  52. {
  53. //LOAD CATEGORY DESCRIPTION
  54. $tmpCategory = get_the_category();
  55. $keywords = single_cat_title('', false);
  56. $description = $tmpCategory[0]->category_description;
  57. }
  58. //PRINT THE VALUES TO THE HEADER SECTION
  59. echo "<!--Auto Keywords Generator -->\n";
  60. //IF THE USER WANTS THE AUTHOR SHOWN THEN DISPLAY THIS INFORMATION
  61. if(get_option("metashowauthor") && $author != "")
  62. echo "<meta name=\"author\" content=\"" . $author . "\" />\n";
  63. //CONTINUE TO PRINT THE REST OF THE META INFORMATION
  64. echo "<meta name=\"keywords\" content=\"" . str_replace("\'", "'", $keywords) . "\" />\n";
  65. echo "<meta name=\"description\" content=\"" . str_replace("\'", "'", $description) . "\" />\n";
  66. echo "<!--Auto Keywords Generator -->\n";
  67. }
  68. function metatagsAdminMenu()
  69. {
  70. //ADD THE HANDLER FOR THE OPTIONS SCREEN
  71. add_options_page("Auto Keywords and Description Tags Generator Options", "Keywords and Description", "administrator", "metaOptions", "metatagsOptionsPage");
  72. }
  73. function metatagsOptionsPage()
  74. {
  75. //USE THE VALUES FROM THE DATABASE INCASE THERE IS NOTHING BEING PASSED IN FROM THE POST
  76. $keywordValue = get_option("metakeywords");
  77. $descValue = get_option("metadescription");
  78. $showauthor = get_option("metashowauthor");
  79. //IF THE USER CLICKED THE SUBMIT BUTTON THEN SAVE THE SETTINGS
  80. if($_POST["hidSubmit"] == 'Y')
  81. {
  82. $keywordValue = $_POST["default_keywords"];
  83. $descValue = $_POST["default_description"];
  84. $showauthor = $_POST["chkshowauthor"];
  85. //UPDATE THE STATIC PAGE OPTIONS FROM WHAT THE USER SUBMITTED
  86. foreach(get_pages() as $tmpPage)
  87. {
  88. update_option($tmpPage->ID . "_keywords", $_POST[$tmpPage->ID . "_keywords"]);
  89. update_option($tmpPage->ID . "_description", $_POST[$tmpPage->ID . "_description"]);
  90. }
  91. //UPDATE THE DEFAULT VALUES
  92. update_option("metakeywords", $keywordValue);
  93. update_option("metadescription", $descValue);
  94. update_option("metashowauthor", $showauthor);
  95. //LET THE USER KNOW THE VALUES HAVE BEEN SAVED
  96. echo "<div class=\"updated\"><p><strong>Your changes have been saved</strong></p></div>\n";
  97. }
  98. //SETUP CHECK STATE FOR CHECK BOXES
  99. if($showauthor == "1")
  100. $authorChecked = "checked";
  101. //PRINT OUT JAVASCRIPT FOR HIDING AND SHOWING DIVS
  102. echo "<script type=\"text/javascript\">\n";
  103. echo "<!--\n";
  104. echo " function toggleVisibility(id) {\n";
  105. echo " var e = document.getElementById(id);\n";
  106. echo " if(e.style.display == \"block\")\n";
  107. echo " e.style.display = \"none\";\n";
  108. echo " else\n";
  109. echo " e.style.display = \"block\";\n";
  110. echo " }\n";
  111. echo "-->\n";
  112. echo "</script>";
  113. echo "<div class=\"wrap\">";
  114. echo " <h3>Auto Meta Tags Generator Options</h3>";
  115. echo " <form name=\"form1\" method=\"post\" action=\"\">";
  116. echo " <input type=\"hidden\" name=\"hidSubmit\" value=\"Y\" />";
  117. echo " <h3>Basic Information</h3>This sections handles the display options as well as the default information for your homepage.<hr/>";
  118. //OUTPUT DISPLAY OPTIONS
  119. echo " <div id=\"poststuff\" class=\"metabox-holder\">";
  120. echo " <div id=\"normal-sortables\" class=\"meta-box-sortables\">";
  121. echo " <div class=\"postbox \">";
  122. echo " <div class=\"handlediv\">";
  123. echo " <br/>";
  124. echo " </div>";
  125. echo " <h3 class=\"hndle\" title=\"Click to toggle\"><span>Display Options</span></h3>";
  126. echo " <div class=\"inside\" style=\"display:block;\">";
  127. echo " <p>Display Author Name: <input type=\"checkbox\" name=\"chkshowauthor\" value=\"1\" " . $authorChecked . " /></p>";
  128. echo " </div>";
  129. echo " </div>";
  130. echo " </div>";
  131. echo " </div>";
  132. //OUTPUT HOMEPAGE INFORMATION
  133. echo " <div id=\"poststuff\" class=\"metabox-holder\">";
  134. echo " <div id=\"normal-sortables\" class=\"meta-box-sortables\">";
  135. echo " <div class=\"postbox \">";
  136. echo " <div class=\"handlediv\">";
  137. echo " <br/>";
  138. echo " </div>";
  139. echo " <h3 class=\"hndle\" title=\"Click to toggle\"><span>Homepage Information</span></h3>";
  140. echo " <div class=\"inside\" style=\"display:block;\">";
  141. echo " <p>Homepage Keywords seperated by commas:<br/><textarea name=\"default_keywords\" style=\"width: 100%; height: 100px;\">" . $keywordValue . "</textarea></p>";
  142. echo " <p>Homepage Description:<br/><textarea name=\"default_description\" style=\"width: 100%; height: 100px;\">" . $descValue . "</textarea></p>";
  143. echo " </div>";
  144. echo " </div>";
  145. echo " </div>";
  146. echo " </div>";
  147. //OUTPUT STATIC PAGES
  148. echo " <h3>Static Page Keywords and Descriptions</h3>Please note that if you use a static page as your home page the above keywords and description will override what you place below.<hr/>";
  149. foreach(get_pages('sort_column=post_title') as $tmpPage)
  150. {
  151. echo "<div id=\"poststuff\" class=\"metabox-holder\" style=\"width: 500px;\">";
  152. echo " <div id=\"normal-sortables\" class=\"meta-box-sortables\">";
  153. echo " <div class=\"postbox \">";
  154. echo " <div class=\"handlediv\" title=\"Click to toggle\" onclick=\"toggleVisibility('div" . $tmpPage->ID . "');\">";
  155. echo " <br/>";
  156. echo " </div>";
  157. echo " <h3 class=\"hndle\" title=\"Click to toggle\" onclick=\"toggleVisibility('div" . $tmpPage->ID . "');\"><span>" . $tmpPage->post_title . "</span></h3>";
  158. echo " <div id=\"div" . $tmpPage->ID . "\" class=\"inside\" style=\"display:none;\">";
  159. echo " <p>Keywords seperated by commas:<br/><textarea name=\"" . $tmpPage->ID ."_keywords\" style=\"width: 100%; height: 100px;\">" . str_replace("\'", "'", get_option($tmpPage->ID . "_keywords")) . "</textarea></p>";
  160. echo " <p>Description:<br/><textarea name=\"" . $tmpPage->ID . "_description\" style=\"width: 100%; height: 100px;\">" . str_replace("\'", "'", get_option($tmpPage->ID . "_description")) . "</textarea></p>";
  161. echo " </div>";
  162. echo " </div>";
  163. echo " </div>";
  164. echo "</div>";
  165. }
  166. //OUTPUT CLOSING AND SUBMIT BUTTON
  167. echo " <p class=\"submit\">";
  168. echo " <input type=\"submit\" name=\"Submit\" value=\"Update Options\"/>";
  169. echo " </p>";
  170. echo " </form>";
  171. echo "</div>";
  172. }
  173. //ADD THE TWO DEFAULT OPTIONS WITH BLANK VALUES
  174. add_option("metakeywords", "");
  175. add_option("metadescription", "");
  176. //REGISTER ADMIN MENU OPTION
  177. add_action("admin_menu", "metatagsAdminMenu");
  178. //REGISTER WORDPRESS_HEAD HOOK
  179. add_action("wp_head", "generateMetaTags");
  180. ?>

comments powered by Disqus