Thêm custom Taxonomy vào wordpress

T

Để thêm custom taxonomy vào website WordPress, bạn thêm đoạn code sau vào file functions.php của theme hoặc child theme:

// your-theme/functions.php

//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'register_language_taxonomy', 0 );
//create a custom taxonomy name it topics for your posts
function register_language_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
 $labels = array(
   'name' => _x( 'Dev Languages', 'Developer languages' ),
   'singular_name' => _x( 'Dev Language', 'Developer language' ),
   'search_items' => __( 'Search Dev Language' ),
   'all_items' => __( 'All Dev Languages' ),
   'popular_items' => __('Popular Dev Languages'),
   'parent_item' => __( 'Parent Dev Language' ),
   'parent_item_colon' => __( 'Parent Dev Language:' ),
   'edit_item' => __( 'Edit Dev Language' ),
   'update_item' => __( 'Update DevLanguage' ),
   'add_new_item' => __( 'Add New Dev Language' ),
   'new_item_name' => __( 'New Dev Language Name' ),
   'menu_name' => __( 'Dev Languages' ),
 );
// Now register the taxonomy
 register_taxonomy('languages',array('post'), array(
   'hierarchical' => false,
   'labels' => $labels,
   'show_ui' => true,
   'show_admin_column' => true,
   'update_count_callback' => '_update_post_term_count',
   'query_var' => true,
   'rewrite' => array( 'slug' => 'language' ),
   'show_in_rest' => true
 ));
}

Trong đoạn code trên mình đã thêm 1 custom taxonomy mới tên là Dev Languages

Tham khảo: codex.wordpress.org

Add Comment

Thích Dev

Mình thích
thì
mình dev hoy

Get in touch

Quickly communicate covalent niche markets for maintainable sources. Collaboratively harness resource sucking experiences whereas cost effective meta-services.

Tags

Dev Languages