Website keywords and web pages describe the friendliness of the Web site to search engines, if their manual plus obviously too frustrating, that how to let WordPress blog automatically for each article automatically keyword and page description. The content of each article is different, how can we let WordPress automatically add article description and keywords? Let's take a look at how to automatically add the article description and keywords to wordpress.
Add the following code to your subject's functions.php file, and the functionality of each code resolves as follows:
Add_action (' Wp_head ', ' wp_keywords '); Add keyword add_action (' wp_head ', ' wp_description ');
Add page description function Wp_keywords () {global $s, $post;
$keywords = '; if (Is_single ()) {//If the article page, the keyword is: Tag + category ID if (get_the_tags ($post->id)) {foreach ($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 homepage keyword ';//home keyword settings} elseif (Is_tag ()) {//Tag page keyword settings $keywords = single_tag_title
(', false ');
} elseif (Is_category ()) {//category page keyword settings $keywords = Single_cat_title (", false);
ElseIf (Is_search ()) {//Search page keyword settings $keywords = esc_html ($s, 1);
else {//default page keyword setting $keywords = Trim (Wp_title (", false));
} if ($keywords) {//output keyword echo "<meta name=\" keywords\ "content=\" $keywords \ "/>\n"; The function wp_description () {Global $s,$post;
$description = ';
$blog _name = get_bloginfo (' name '); if (Is_singular ()) {//article page if there is a Description field, display the description, otherwise intercept the article content if (! empty ($post->post_excerpt)) {$text = $post->post_exc
Erpt;
else {$text = $post->post_content; $description = Trim (str_replace (Array ("\ r \ n", "\ r", "\ n", "", ""), "", Str_replace ("\" "," ","), S
Trip_tags ($text))); if (!
($description)) $description = $blog _name. "-" .
Trim (Wp_title (", false)); ElseIf (Is_home ()) {//home page display description Settings $description = $blog _name. "-" . Get_bloginfo (' description '). ' First page to show the description '; First page to add yourself} elseif (Is_tag ()) {//Tab display description Settings $description = $blog _name. "About '." Single_tag_title (', false ').
"' The article"; ElseIf (Is_category ()) {//category page display description settings $description = $blog _name. "About '." Single_cat_title (', false ').
"' The article"; ElseIf (Is_archive ()) {//Document page display description setting $description = $blog _name. "In:". Trim (Wp_title (", false)).
"' The article"; } elseif (Is_search ()) {//Search page display description set $Description = $blog _name. ": '" . Esc_html ($s, 1).
"' Search results"; else {//default other page display description setting $description = $blog _name. "About '." Trim (Wp_title (", false)).
"' The article"; ///Output Description $description = mb_substr ($description, 0,, ' utf-8 ').
'..';
echo "<meta name=\" description\ "content=\" $description \ "/>\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 ', ' <strong> '. $sr. ' </strong> ', $text);
}
return $text;
}
Add_filter (' the_excerpt ', ' wps_highlight_results ');
Add_filter (' The_title ', ' wps_highlight_results ');
Use this snippet to highlight search terms in your blog search results the_excerpt and the_title.