• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to user navigation

PopWP

WordPress and Genesis Tutorials

  • Get Started
  • About
  • Archive
  • Services
  • Membership
  • My Account

Conditionally change post info on Custom Post Types

Last Updated on March 31, 2020 Favorited: 1 times

//Filter the Taxonomy info on a CPT
add_filter( 'genesis_post_info','genesiskit_post_info_filter', 11 );
function genesiskit_genesis_post_info_filter( $post_info ) {
	if ( 'portfolio' == get_post_type() ) { //swap in CPT name
		$post_info='<span class="author">[post_author_posts_link]</span> <span class="categories">[post_terms taxonomy="portfolio-type" before=""]</span> <span class="date">[post_modified_date]</span>';//swap in taxonomy and label name
		return $post_info;
	}
	elseif ( 'post' == get_post_type() ) {
		return $post_info;
	}
}

//* Add author gravatar before post meta on custom post types.
add_action( 'genesis_entry_header', 'genesiskit_entry_gravatar' , 11 );
function genesiskit_entry_gravatar() {
    if ( ! is_singular('portfolio') ) {
        return;
    }
        echo get_avatar( get_the_author_meta( 'email' ), 96 );
}

for WooCommerce Products

//Filter the Taxonomy info on a CPT
add_filter( 'genesis_post_info','dy_post_info_filter', 11 );
function dy_genesis_post_info_filter( $post_info ) {

	if ( 'product' == get_post_type() ) { //swap in CPT name
		$post_info='<span class="categories">'; //swap in taxonomy and label name
		return $post_info;
    }
    
	elseif ( 'post' == get_post_type() ) {
		return $post_info;
	}
}

 

Categories: Free Content, Snippets

Reader Interactions

Primary Sidebar

Search

WPEngine WordPress Hosting, Perfected.

Hosting You are looking for?.
Perfect solution for small business to global enterprise.

Learn more

StudioPress Genesis Theme Framework

The No.1 Theme Provider.
Creative, SEO rich Theme for all niche projects.

Learn more

Categories

  • Free Content
  • Genesis Tutorials
  • Premium Content
  • Snippets
  • What's New?
  • WordPress Tutorials

Tag Cloud

Archive Background Section blog canvas menu center logo columns conditional tags CSS CSS Grid custom Customizer custom post type Custom Post Types custom template Custom Widget effect eNews Extended Featured Image front-page Genesis Genesis Sample header right hero section Image Background js layout left menu Logo menu Navigation Menu newsletter post page related posts responsive menu search search widget Shrinking Logo site header slide in-out Stylesheet Template Utility Bar Video Background widgets WordPress

Built with Genesis Framework + WordPress by Aryan Raj

  • Contact
  • FAQ
  • Disclaimer
  • Privacy Policy
  • Copyright Policy
  • Terms of Service