David Stockdale's Scrapcode

Adding tags to posts

Something I meant to add a while ago.

How to add tags to pages and ensure they are included in tag queries.

Simply add this to “function.php”.

/**
 * ADD Tags to Pages see https://www.sitepoint.com/wordpress-pages-use-tags/
 */
function tags_support_all() {
	register_taxonomy_for_object_type('post_tag', 'page');
}

/**
 * Ensure all tags are included in queries.
 */
function tags_support_query($wp_query) {
	if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
}

/**
 * Tag hooks.
 */
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');

Leave a Reply