WordPress Tutorial

WordPress adds tutorial codes for custom fields to categories and labels

 Alibaba Cloud

Previously shared WordPress Add the tutorial code of the category keyword custom field. This time, the core code of the category keyword custom field is the same as that of the category keyword custom field optimization And expand and add the hook function of the label. The following is an example code of the custom field of the custom title, custom keyword and custom description for the classification and label.

Add the following code to the theme The functions.php file of:

Want to be here? contact us bar
 Maker host
  1.  <? php 
  2.  function boke8_net_add_category_field ( ) {
  3. 	 echo  '<div class="form-field">
  4.  <label for="tag title">Customize the title</label>
  5.  <input name="tag-title" id="tag-title" type="text" value="" size="40">
  6.  <p>Please enter here for SEO Optimized title</ p>
  7.  </div>' ;	
  8. 	 echo  '<div class="form-field">
  9.  <label for="tag keywords">Custom keywords</label>
  10.  <input name="tag-keywords" id="tag-keywords" type="text" value="" size="40">
  11.  <p>Please enter keywords for SEO optimization here</ p>
  12.  </div>' ;		  
  13. 	 echo  '<div class="form-field">
  14.  <label for="tag description">User defined description</label>
  15.  <textarea name="tag-description" id="tag-description" class="large-text" rows="5" cols="50"></textarea>
  16.  <p>Please enter keywords for SEO optimization here</ p>
  17.  </div>' ;		  
  18.  }
  19.   
  20.  function boke8_net_edit_category_field ( $tag ) {
  21. 	 echo  '<tr class="form-field">
  22.  <th scope="row"><label for="tag title">Custom title</label></th>
  23.  <td>
  24.  <p><input name="tag-title" id="tag-title" type="text" value="' ;
  25. 				 echo get_option ( '_category_title' . $tag -> term_id ) . '" size="40"/></p>
  26.  <p class="description">Please enter the title for SEO optimization here</ p>
  27.  </td>
  28.  </tr>' ;
  29.   
  30. 	 echo  '<tr class="form-field">
  31.  <th scope="row"><label for="tag keywords">user-defined keywords</label></th>
  32.  <td>
  33.  <p><input name="tag-keywords" id="tag-keywords" type="text" value="' ;
  34. 				 echo get_option ( '_category_keywords' . $tag -> term_id ) . '" size="40"/></p>
  35.  <p class="cat url">Please enter keywords for SEO optimization here</ p>
  36.  </td>
  37.  </tr>' ;	
  38.   
  39. 	 echo  '<tr class="form-field">
  40.  <th scope="row"><label for="tag description">User defined description</label></th>
  41.  <td>
  42.  <p><textarea name="tag-description" id="tag-description" class="large-text" rows="5" cols="50">' . get_option ( '_category_description' . $tag -> term_id ) . '</textarea></p>
  43.  <p class="cat url">Please enter a description for SEO optimization here</ p>
  44.  </td>
  45.  </tr>' ;		
  46.  }
  47.   
  48.  function boke8_net_taxonomy_metadate ( $term_id ) {
  49. 	 if ( isset ( $_POST [ 'tag-title' ] )  &&  isset ( $_POST [ 'tag-keywords' ] )  &&  isset ( $_POST [ 'tag-description' ] ) ) {
  50.   
  51. 		 if ( ! current_user_can ( 'manage_categories' ) ) {
  52. 			 return  $term_id ;
  53. 		 }
  54.   
  55. 		 $title_key  =  '_category_title' . $term_id ;  //The key option is cat-tel-1 type
  56. 		 $title_value  =  $_POST [ 'tag-title' ] ;	 // value
  57.   
  58.   
  59. 		 $word_key  =  '_category_keywords' . $term_id ;
  60. 		 $word_value  =  $_POST [ 'tag-keywords' ] ;
  61.   
  62. 		 $desc_key  =  '_category_description' . $term_id ;
  63. 		 $desc_value  =  $_POST [ 'tag-description' ] ;		
  64.   
  65.   
  66.  update_option (  $title_key ,  $title_value  ) ; 
  67.  update_option (  $word_key ,  $word_value  ) ;
  68.  update_option (  $desc_key ,  $desc_value  ) ;
  69. 	 }
  70.  } 
  71.   
  72.  add_action ( 'category_add_form_fields' , 'boke8_net_add_category_field' , ten , two ) ;
  73.  add_action ( 'category_edit_form_fields' , 'boke8_net_edit_category_field' , ten , two ) ;
  74.  add_action ( 'created_category' , 'boke8_net_taxonomy_metadate' , ten , one ) ;
  75.  add_action ( 'edited_category' , 'boke8_net_taxonomy_metadate' , ten , one ) ;
  76.   
  77.  add_action (  'post_tag_add_form_fields' ,  'boke8_net_add_category_field' , ten , two ) ;  
  78.  add_action (  'post_tag_edit_form_fields' ,  'boke8_net_edit_category_field' , ten , two ) ;  
  79.  add_action (  'edited_post_tag' ,  'boke8_net_taxonomy_metadate' , ten , one ) ;  
  80.  add_action (  'create_post_tag' ,  'boke8_net_taxonomy_metadate' , ten , one ) ;
  81.  ?>

Call output code

  1.  echo get_option ( '_category_title' . get_queried_object_id ( ) ) ;
  2.  echo get_option ( '_category_keywords' . get_queried_object_id ( ) ) ;
  3.  echo get_option ( '_category_description' . get_queried_object_id ( ) ) ;

The code is simple. You can copy it directly or add more custom fields by reference.

WordPress adds tutorial codes for custom fields to categories and labels

135 people have purchased
View Demo Upgrade VIP Buy Now

Collection
fabulous ( zero )

Post reply

Hot selling template

Ashade - Works exhibition photo album WordPress Chinese theme
 LensNews

This site accepts WordPress/PbootCMS/DedeCMS, etc
System construction, imitation, development, customization and other services!