Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create custom taxonomy for post type page

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 273
    Comment on it

    Hello readers, today we will discuss "how you can add category for post type page".

    When a user install the WordPress, user will only get category for "post type post".

    If user want to add taxonomy or category for "post type page", then user need to add below code.

    <?php
    function add_custom_taxonomies() {
        // Add new "Locations" taxonomy to Posts
        register_taxonomy('location', 'page', array(
            // Hierarchical taxonomy (like location)
            'hierarchical'      => true,
            // This array of options controls the labels displayed in the WordPress Admin UI
            'labels'            => array(
                'name'              => _x('Locations', 'taxonomy general name' ),
                'singular_name'     => _x('Location', 'taxonomy singular name' ),
                'search_items'      =>  __( 'Search Locations' ),
                'all_items'         => __( 'All Locations' ),
                'parent_item'       => __( 'Parent Location' ),
                'parent_item_colon' => __( 'Parent Location:' ),
                'edit_item'         => __( 'Edit Location' ),
                'update_item'       => __( 'Update Location' ),
                'add_new_item'      => __( 'Add New Location' ),
                'new_item_name'     => __( 'New location Name' ),
                'menu_name'         => __( 'Locations' ),
            ),
    
            // Control the slugs used for this taxonomy
            'rewrite'           => array(
                'slug'              => 'location', // need to change as you want
                'with_front'        => false, // Don't display the category base before "/locations/"
                'hierarchical'      => true // This will allow URL's like "/locations/boston/cambridge/"
            ),
        ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: