Remove Post Info and Post Meta from Custom Post Types in Genesis Theme in WordPress
After creating custom post types in WordPress on a Genesis theme by default the post info is displayed which contains the post author, post date and comments info and the post meta is also displayed which contains the category and tag values.
You may want to have these values removed for your custom post types but leave them intact for regular posts. This is possible by adding an action and function in your themes functions.php file:
add_action ( 'genesis_before_loop', 'themeprefix_remove_post_info' ); // Remove Post Info, Post Meta from CPT function themeprefix_remove_post_info() { if ('custom_post_type_name' == get_post_type()) {//add in your CPT name remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); } }
All you need to swap in the above code is your custom_post_type name in the if statement. Then these post info and post meta data is removed just from that custom post type.
The remove action for the genesis_post_info has a priority number set (12), this is because the original action is added with this number in the post.php file in the structure directory of the Genesis framework. To remove the original action they have to be exactly the same.
Remove Post Info and Meta from all CPTs apart from Posts
I find that I typically only use post info and post meta on posts only and not any other custom post types, you could add a catch all piece of code to prevent the post info and post meta from appearing in any post type apart from posts by using the not equals operator !
add_action ( 'genesis_before_loop', 'themeprefix_remove_post_info' ); /** * Remove Post Info and Post Meta on all CPTs but leave on posts */ function themeprefix_remove_post_info() { if ( 'post' !== get_post_type() ) {//add in your CPT name remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); } }
So in the code snippet anything other then posts will not have the info and metas because of
'post' !== get_post_type()
Does this also work on removing date/author on attachment posts?
The post is most informative about genesis. It helped me know all about it at a first read itself. :)
I have set up a custom post type called “News” and I created a custom taxonomy with “New Categories” and “News Tags” so that I hopefully have not confused them with the regular “Categories” and “tags” used in the blog. On my “News” archive and single post pages the top post info item show up, but the bottom post meta does not.
While trying hard to find out why the post meta isn’t showing up in my News archive, your post implies that it should show up by default! And here you’re showing how to remove them!
Well, I reverse engineered your code above to try this:
// Add back Post Meta to CPT
function add_back_post_info() {
if ('news' == get_post_type()) {//add in your CPT name
add_action( 'genesis_entry_footer', 'genesis_post_meta' );
}
}
But I’m not getting anything. So my question is sort of backwards here. But I guess I’m stumped as to why my custom post type ISN’T showing the post_meta to begin with?
Lines 492 to 503 in post.php state:
* Echo the post meta after the post content.
*
* By default, only does post meta on posts.
*
* The post info makes use of a couple of shortcodes by default, and the whole output is filtered via
* `genesis_post_meta` before echoing.
*
* @since 0.2.3
*
* @uses genesis_markup() Contextual markup.
*
* @return null Return early if post type lacks support.
So needless to say, I’m confused as to what’s true about this.
You need to ensure that your CPT has taxonomy support which is done in the $args in register_post_type – see this Gist I use for my CPTs – https://gist.github.com/neilgee/8926914#file-cpt-genesis-php and check here for further explanation – https://codex.wordpress.org/Function_Reference/register_post_type#taxonomies
Neil,
I know it’s been awhile since you posted this, but I just used this code on a site! This is my first time digging this deep into Genesis, and your site has come up a few times in my many searches.
Thanks!
Thanks for the feedback Glenn