This tutorial is going to show you how to add support for custom post type and output post tags to your WordPress template.
For instance, your template comes with custom posts called “Services” (or “Clients”, “Our team”, “Slides” depending on your template) and you want to add tags to it. To do this,
- Open the theme-init.php file located in the \wp-content\themes\theme###\includes folder on your server to edit.
- Look for the part of code related to your custom post. E.g.
- Save the changes and update the file on your server with them.
- Now you can log into your WordPress admin and open the custom posts menu. You will find new options there like “Tags” and “Categories” that previously were available in the Posts only.
/* Services */
function my_post_type_services() {
register_post_type( 'services',
array(
'label' => __('Services'),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'rewrite' => array(
'slug' => 'services-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'thumbnail',
'editor')
)
);
}
Where you need to change this part
'supports' => array(
'title',
'thumbnail',
'editor')
)
);
}
To
'supports' => array(
'title',
'thumbnail',
'editor'
),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
));
The whole part will look like this
/* Services */
function my_post_type_services() {
register_post_type( 'services',
array(
'label' => __('Services'),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'rewrite' => array(
'slug' => 'services-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'thumbnail',
'editor'
),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
));
}
Feel free to check the detailed video tutorial below:
WordPress. How to enable and output post tags for custom post types