In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to automatically add keywords to WordPress articles. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Add the following code to the functions.php file of your theme, and the function of each code is parsed as follows:
Add_action ('wp_head',' wp_keywords'); / / add the keyword add_action ('wp_head',' wp_description'); / / add page description function wp_keywords () {global $s, $post; $keywords ='' If (is_single ()) {/ / if it is an article page, the key words are: tag + category ID if (get_the_tags ($post- > ID)) {foreach (get_the_tags ($post- > ID) as $tag) $keywords. = $tag- > name. Foreach (get_the_category ($post- > ID) as $category) $keywords. = $category- > cat_name. ','; $keywords = substr_replace ($keywords,',-2);} elseif (is_home ()) {$keywords ='I am the home keyword'; / / homepage keyword setting} elseif (is_tag ()) {/ / tag page keyword setting $keywords = single_tag_title (', false);} elseif (is_category ()) {/ / Classification page keyword setting $keywords = single_cat_title (', false) } elseif (is_search ()) {/ / search page keyword setting $keywords = esc_html ($s, 1);} else {/ / default page keyword setting $keywords = trim (wp_title (', false));} if ($keywords) {/ / output keyword echo "\ n";}} function wp_description () {global $s, $post; $description ='; $blog_name = get_bloginfo ('name') If (is_singular ()) {/ / the article page displays the description if there is a description field, otherwise intercepts the article content if (! Empty ($post- > post_excerpt) {$text = $post- > post_excerpt;} else {$text = $post- > post_content;} $description = trim (str_replace (array ("\ r\ n", "\ r", "\ n", "", "), str_replace ("\ ","'", strip_tags ($text); if (! ($description)) $description = $blog_name. "-". Trim (wp_title (', false));} elseif (is_home ()) {/ / Home display description setting $description = $blog_name. "-". Get_bloginfo ('description'). The description to be displayed on the home page'; / / add your own elseif (is_tag ()) {/ / tab display description setting $description = $blog_name. "about'". Single_tag_title ('', false). "'s article";} elseif (is_category ()) {/ / the category page displays the description setting $description = $blog_name. "about'". Single_cat_title ('', false). Elseif (is_archive ()) {/ / document page display description setting $description = $blog_name. "in:'" Trim (wp_title (', false)). Elseif (is_search ()) {/ / the search page shows the description setting $description = $blog_name. ":'". Esc_html ($s, 1). "search results of'";} else {/ / default other pages display description setting $description = $blog_name. "about'". Trim (wp_title (', false)). Output description $description = mb_substr ($description, 0220, 'utf-8'). '..'; echo "\ n";}
Highlight keywords in search results:
Function wps_highlight_results ($text) {if (is_search ()) {$sr = get_query_var ('s'); $keys = explode ("", $sr); $text = preg_replace ('/ ('implode (', $keys).) / iu','. $sr.'', $text);} return $text;} add_filter ('the_excerpt',' wps_highlight_results'); add_filter ('the_title',' wps_highlight_results')
Use this code snippet to highlight search terms in your blog search results the_excerpt and the_title.
This is the end of the article on "how to automatically add keywords to WordPress articles". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.