How to Add Tags to Custom Post Type?

Lets say you have used the following code to register a custom post –

# Registering Custom Post Type News
add_action( ‘init’, ‘register_blogpost’, 20 );

function register_blogpost() {

$args = array(
‘labels’ => array(
‘name’ => ‘Blog’,
‘add_new_item’ => ‘Add New Blog’
),

‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘author’, ‘thumbnail’, ‘comments’, ‘revisions’, ‘post-formats’),
‘show_in_menu’ => true,
‘menu_position’ => 1.1,
‘menu_icon’ => “dashicons-format-aside”,
‘publicly_queryable’ => true,
‘public’ => true,
‘has_archive’ => true,
‘capability_type’ => ‘post’
);
register_post_type( ‘blogs’, $args );//max 20 charachter cannot contain capital letters and spaces
}

add_action( ‘init’, ‘create_blogs_tag_taxonomies’, 0 );

You can add the following codes into your functions.php to add Tags to your custom post

add_action( ‘init’, ‘create_blogs_tag_taxonomies’, 0 );

//create two taxonomies, genres and tags for the post type “tag”
function create_blogs_tag_taxonomies()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
‘name’ => _x( ‘Tags’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Tag’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Search Tags’ ),
‘popular_items’ => __( ‘Popular Tags’ ),
‘all_items’ => __( ‘All Tags’ ),
‘parent_item’ => null,
‘parent_item_colon’ => null,
‘edit_item’ => __( ‘Edit Tag’ ),
‘update_item’ => __( ‘Update Tag’ ),
‘add_new_item’ => __( ‘Add New Tag’ ),
‘new_item_name’ => __( ‘New Tag Name’ ),
‘separate_items_with_commas’ => __( ‘Separate tags with commas’ ),
‘add_or_remove_items’ => __( ‘Add or remove tags’ ),
‘choose_from_most_used’ => __( ‘Choose from the most used tags’ ),
‘menu_name’ => __( ‘Tags’ ),
);

register_taxonomy(‘tag’,’blogs’,array(
‘hierarchical’ => false,
‘labels’ => $labels,
‘show_ui’ => true,
‘update_count_callback’ => ‘_update_post_term_count’,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘tag’ ),
));
}
?>

Please remember that the second parameter in the register_taxonomy function is the custom post you registered.