Tutorials

WordPress Tutorial: Create a custom taxonomy
Tutorials / 12th February 2017

Custom taxonomies can be used in WordPress to organise posts and custom post types similarly to how posts are organised into categories. In fact categories are a type of taxonomy to organise posts. An example of a custom taxonomy may be a ‘genre’ taxonomy to organise review posts, or a ‘location’ taxonomy to organise listings by area. Similarly to creating a custom post type (previous post here), with a few lines of PHP code it is very easy to create a simple custom taxonomy without the use of a plugin as I will show you in this tutorial. Open your theme’s Functions.php file Along the side of the WordPress dashboard options, hover to ‘Appearance’ then click on ‘Editor’. Once in the Theme Editor, find Theme Functions (functions.php) file in the list on the right of your screen and click on it to open it. Create a new function for your custom post type Enter the following sample of code into your functions.php file, changing the name of the function (create_custom_taxonomy) to any other name if you wish. But do not yet update the file. function create_new_taxonomy() { } Register the post type Enter the following code sample (underlined) between the { }…

WordPress Tutorial: Create a custom post type
Tutorials / 5th February 2017

Custom post types can be used in your WordPress setup to create customised content similar to regular posts but with some differences. With a few lines of PHP code it is very easy to create a custom post type without the use of a plugin as I will show you in this tutorial. Open your theme’s Functions.php file Along the side of the WordPress dashboard options, hover to ‘Appearance’ then click on ‘Editor’. Once in the Theme Editor, find Theme Functions (functions.php) file in the list on the right of your screen and click on it to open it. Create a new function for your custom post type Enter the following sample of code into your functions.php file, changing the name of the function (my_custom_posttype) to any other name if you wish. But do not yet update the file. function my_custom_posttype() { } Register the post type Enter the following code sample (underlined) between the { } brackets: function my_custom_posttype() { register_post_type( ‘event’, array( ‘labels’ => array( ‘name’ => __( ‘Events’ ), ‘singular_name’ => __( ‘Event’ ) ), ‘has_archive’ => true, ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘wpb_post_views_count’), ‘taxonomies’ => array( ‘category’ ), ) ); } As an example, here I am…