Enable Tags on Pages in WordPress

30th July 2014

Reading Time:

It’s easy enough to add tags to posts in WordPress, but the default functionality doesn’t offer tags on pages. Luckily WordPress treats posts and pages pretty much the same, it’s an easy fix to add this to your project.

Open up your functions.php file and insert the following:

    // add tag support to pages
    add_action( 'init', 'tags_support_all');
    function tags_support_all() {
        register_taxonomy_for_object_type('post_tag', 'page');
    }
    // ensure all tags are included in queries
    add_action( 'pre_get_posts', 'tags_support_query');
    function tags_support_query($wp_query) {
        if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
    }

I stumbled upon this one at Sitepoint, a pretty handy source for helpful WordPress bits n’ bobs.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *