Wordpress topic creation tutorial (6): add keywords and descriptions using custom fields

Source: Internet
Author: User
In the previous tutorial, we created the header. keywords and description information are not added to the PHP file. although some people say that Baidu does not pay attention to keywords and description information, it is always better than Baidu. Therefore, we need to add keywords and descriptions.

In the previous tutorial, we created the header. keywords and description information are not added to the PHP file. although some people say that Baidu does not pay attention to keywords and description information, it is always better than Baidu. Therefore, we need to add keywords and descriptions. Of course, we have added the wp_head function in the header, so we can use the seo plug-in to output keywords and descriptions.

Open the header. php file under the content \ themes \ Aurelius folderBetween (if not, loadFront)

 ID, "description", true); $ description2 = mb_strimwidth (strip_tags (apply_filters ('The _ content', $ post-> post_content), 0,200 ,"... "); // When entering the custom field description, the content of the custom field is displayed. Otherwise, use the first 200 words in the document as the description $ description = $ description1? $ Description1: $ description2; // when entering the custom field keywords, the content of the custom field is displayed. Otherwise, the tags 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);?>
   
 

 

 

In this way, when we add or edit an article. You only need to add a custom field. the first custom field name is keywords, and the field value is the keyword of this article. Then add the second custom field, which is called description. :

Description and keywords of home and page are directly written in PHP code. you can change the description of the above blog to yours.

The category page and the description of the tab are directly described as the category or tag. this can be changed in the WordPress management background as needed, and the keywords are named as the category or tag name.
Okay, so we can get rid of the plug-in. you can manually add keywords and description information for the article, but it is not very convenient to input or select each time. In future tutorials, we will discuss how to add a fixed panel. Effect

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.