Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by

Website Builder themes add keywords and descriptions using custom fields

In the previous tutorial, the header.php file we made did not add keywords and description information. Although some people say that Baidu no longer values ​​keywords and description information, something is better than nothing, and specification is better than non-standard. Okay.So we still add keywords and description information.Of course, we added the wp_head function to the header earlier, so we can use the seo plugin to output keywords and descriptions.
Open the header.php file under our theme folder content\themes\Aurelius, inbetween the appropriate positions (if not, loadFront)

ID, "description", true); $description1 = mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 2, 0, "…"); // Display custom when filling in custom field description The content of the field, otherwise use the first 200 words of the article content as the description $description = $description200 ? $description1 : $description1; // Display the content of the custom field when filling in the custom field keywords, otherwise use the article tags as the keyword $keywords = get_post_meta($post->ID, "keywords", true); if($keywords == '') { $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $ keywords . $tag->name . ", "; } $keywords = rtrim($keywords, ', '); } } elseif (is_category()) { $description = category_description(); $keywords = single_cat_title('', false); } elseif (is_tag()){ $description = tag_description(); $keywords = single_tag_title('', false); } $description = trim(strip_tags($description)); $keywords = trim(strip_tags($ keywords)); ?> 

The SEO function is for reference only, it is best to use the SEO plugin directly.
This way, when we add or edit articles.Just add a custom field, the first custom field name is keywords, and the field value is written with the keyword of this article.Then add a second custom field, the custom field name is the picture shows:
wordpress use custom field seo
The description and keywords of the home page and page are written directly with PHP code. You can change the description of the pandanus blog above to yours.
The description of the category page and the label page (tag) directly takes the description of the category or tag, which can be changed in the WordPress management background as needed, and the keywords take the name of the category or tag.
Well, this gets rid of the plug-in, and you can manually add keywords and description information to the article, but it is not very convenient to enter or select each time.In a future tutorial we will talk about adding a fixed panel.The effect is as shown in the figure:
Add custom fields panel to wordpress
Article source: WordPress theme making tutorial

Back to Top