Adding categories and tags to pages

In this article I am showing how to add the category and tags to pages.

First registering the category and tags taxonomy to “page” type by init and register_taxonomy_for_object_type functions. After adding this code “Categories” and “Tags” meta box will appear on Page Add/Edit Screen at Dashboard.

/** Enabling Categories and Tags Taxonomy for pages at Add/Edit Screen
 * 
 * @since 1.0
 * 
 */ 
add_action('init', 'gd_register_category_tags_taxonomy_for_page');
function gd_register_category_tags_taxonomy_for_page() {
	register_taxonomy_for_object_type('post_tag', 'page');
	register_taxonomy_for_object_type('category', 'page'); 
}

Adding opening and closing footer markup. genesis_page_entry_footer_markup_open is creating the opening footer markup <footer class="entry-footer"> and genesis_page_entry_footer_markup_close is making the closing footer markup </footer>

add_action( 'genesis_entry_footer', 'genesis_page_entry_footer_markup_open', 5 );
add_action( 'genesis_entry_footer', 'genesis_page_entry_footer_markup_close', 15 );
/**
 * Echo the opening structural markup for the entry footer.
 *
 * @since 2.0.0
 *
 * @uses genesis_attr() Contextual attributes.
 */
function genesis_page_entry_footer_markup_open() {

	if ( 'page' === get_post_type() )
		printf( '<footer %s>', genesis_attr( 'entry-footer' ) );

}

/**
 * Echo the closing structural markup for the entry footer.
 *
 * @since 2.0.0
 */
function genesis_page_entry_footer_markup_close() {

	if ( 'page' === get_post_type() )
		echo '</footer>';

}

Now display the page meta. genesis_post_meta function is executing for “post” type. I created a new function “genesis_page_meta” which is executing for “page” type.

add_filter( 'genesis_page_meta', 'do_shortcode', 20 );
add_action( 'genesis_entry_footer', 'genesis_page_meta' );
/**
 * Echo the page meta after the page content.
 *
 * The page info makes use of a couple of shortcodes by default, and the whole output is filtered via
 * <code>genesis_post_meta</code> before echoing.
 *
 * @since 0.2.3
 *
 * @uses genesis_markup() Contextual markup.
 *
 * @return null Return early if on a page
 */
function genesis_page_meta() {

	if ( 'post' === get_post_type() )
		return;

	$output = genesis_markup( array(
		'html5'   =&gt; '&lt;p %s&gt;',
		'xhtml'   =&gt; '&lt;div class=&quot;post-meta&quot;&gt;',
		'context' =&gt; 'entry-meta-after-content',
		'echo'    =&gt; false,
	) );

	$output .= apply_filters( 'genesis_page_meta', 'Filed Under: Genesis ' );
	$output .= genesis_html5() ? '&lt;/p&gt;' : '&lt;/div&gt;';

	echo $output;

}

Here is the full snippet. You will add the following code in your functions.php file.

Share This Article

Subscribe Membership Plan ($9.99/mo)

  • Get full access to all premium tutorials
  • Get Support for the posted content
  • Request for specific how-to tutorials
  • Cancel the subscription at anytime

Reader Interactions

3 Discussion to This Post

  1. Hi, great post here!

    I have now meta dispalyed on pages but I would like to:
    * Display categories above and not below the page content
    * Change the label (e.g. from “File under” to “Categorie”)
    For posts I’m doing that using Simple Edits Plugin.

    How I could do that for pages as well please?

    Many thanks in advance

    S

    • Replace line no 26, 27 & 28 with

      add_action( 'genesis_entry_header', 'genesis_page_entry_footer_markup_open', 20 );
      add_action( 'genesis_entry_header', 'genesis_page_entry_footer_markup_close', 25 );
      add_action( 'genesis_entry_header', 'genesis_page_meta', 20 );
      

      And replace [post_categories] with [post_categories before="Categories "]

  2. That is beautiful, man. Worked just how it should. Thank you for your code! So weird that my Gen child theme didn’t come with that. Are categories now bad for pages?

Leave A Reply

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