- This topic has 17 replies, 3 voices, and was last updated 6 years, 1 month ago by Tom.
-
AuthorPosts
-
June 14, 2017 at 9:23 pm #333793Paul
Hi Guys,
I have been through the forum thoroughly and can’t get Author and other meta data to show.
It all shows on my normal blog page but not on my custom post type page.
1.) I’m aware that by default on Custom Post Types meta data doesn’t show
2.) I’ve added the code recommended on another post to my functions.php and its still not working:
if ( ! function_exists( ‘generate_post_meta’ ) ) :
/**
* Build the post meta
*
* @since 1.3.29
*/
add_action( ‘generate_after_entry_title’, ‘generate_post_meta’ );
function generate_post_meta()
{
if ( ‘post’ == get_post_type() || ‘review’ == get_post_type() ) : ?><?php generate_posted_on(); ?><!– .entry-meta –>
<?php endif;
}
endif;if ( ! function_exists( ‘generate_footer_meta’ ) ) :
/**
* Build the footer post meta
*
* @since 1.3.30
*/
add_action( ‘generate_after_entry_content’, ‘generate_footer_meta’ );
function generate_footer_meta()
{
if ( ‘post’ == get_post_type() || ‘review’ == get_post_type() ) : ?>
<footer class=”entry-meta”>
<?php generate_entry_meta(); ?>
<?php if ( is_single() ) generate_content_nav( ‘nav-below’ ); ?>
</footer><!– .entry-meta –>
<?php endif;
}
endif;Can you please help
Cheers
Paul
June 14, 2017 at 11:34 pm #333820TomLead DeveloperLead DeveloperI would do this:
add_action( 'after_setup_theme','tu_remove_entry_meta' ); function tu_remove_entry_meta() { remove_action( 'generate_after_entry_content', 'generate_footer_meta' ); remove_action( 'generate_after_entry_title', 'generate_post_meta' ); } add_action( 'generate_after_entry_title', 'tu_cpt_post_meta' ); function tu_cpt_post_meta() { if ( 'post' == get_post_type() || 'review' == get_post_type() ) : ?> <div class="entry-meta"> <?php generate_posted_on(); ?> </div><!-- .entry-meta --> <?php endif; } add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' ); function tu_cpt_footer_meta() { if ( 'post' == get_post_type() || 'review' == get_post_type() ) : ?> <footer class="entry-meta"> <?php generate_entry_meta(); ?> <?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?> </footer><!-- .entry-meta --> <?php endif; }
This of course assumes that your CPT is named: review
June 14, 2017 at 11:52 pm #333829PaulAll works thanks heaps.
June 14, 2017 at 11:53 pm #333831TomLead DeveloperLead DeveloperYou’re welcome 🙂
June 15, 2017 at 12:07 am #333837PaulNow i’m trying to enable Co-Authors Plus which requires some changes. See:
https://generatepress.com/forums/topic/co-author-plus/
And it won’t work on the Custom Post Type. I added the code above to Template Tags in the child theme.
How do I get that to work with the code you added above?
Thanks heaps
June 15, 2017 at 10:49 am #334057TomLead DeveloperLead DeveloperHi Paul,
Try this instead: https://gist.github.com/generatepress/b5bb793b79c2274aee4e
June 15, 2017 at 6:55 pm #334231PaulExcellent, We’re almost there.
Only thing now with that code change is on both my blog and custom post type. Author and Date now look like this:
June 13, 2017Melisa Grigg
(It’s lost the space and the “by”)
Instead of:
June 13, 2017 by Melisa Grigg
Thanks heaps for all your help
June 15, 2017 at 11:01 pm #334303TomLead DeveloperLead DeveloperJust updated the code. Can you try again?
June 15, 2017 at 11:33 pm #334313PaulIt was pretty good. Was just missing a space before the b on “by”
If you want to update your code.
Thanks for your help
June 16, 2017 at 9:19 am #334544TomLead DeveloperLead DeveloperUpdated. Thanks! 🙂
February 14, 2018 at 7:42 am #496259MiroslavWhere do you put that code, Tom? And, why doesn’t the
|| 'review' == get_post_type()
solution work?February 14, 2018 at 9:55 pm #496877TomLead DeveloperLead DeveloperPHP can be added like this: https://docs.generatepress.com/article/adding-php/
That solution should work if the currently viewed post type is: review
February 15, 2018 at 8:19 am #497347MiroslavThanks, I thought it was supposed to be placed in the inc/structure/post-meta.php file (of my child theme).
February 15, 2018 at 10:28 am #497471TomLead DeveloperLead DeveloperGlad I could help 🙂
February 26, 2018 at 7:25 am #506006PaulHi Tom,
Just need to add categories and tags to custom post type as they aren’t showing by default. I’m close I just dont know how to only show the custom taxonomies below only if there is one for the post. e.g. It’s currently showing an icon even if the article doesn’t have a category.
Got this code:
add_action( 'after_setup_theme','tu_remove_entry_meta' ); function tu_remove_entry_meta() { remove_action( 'generate_after_entry_content', 'generate_footer_meta' ); remove_action( 'generate_after_entry_title', 'generate_post_meta' ); } add_action( 'generate_after_entry_title', 'tu_cpt_post_meta' ); function tu_cpt_post_meta() { if ( 'post' == get_post_type() || 'club' == get_post_type() ) : ?> <div class="entry-meta"> <?php generate_posted_on(); ?> </div><!-- .entry-meta --> <?php endif; } add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' ); function tu_cpt_footer_meta() { if ( 'post' == get_post_type() || 'club' == get_post_type() ) : ?> <footer class="entry-meta"> <?php generate_entry_meta(); ?> <span class="cat-links"><?php echo get_the_term_list( $post->ID, 'club_category', $before = '', ', ' ); ?></span> <span class="tags-links"><?php echo get_the_term_list( $post->ID, 'club_tags', $before = '', ', ' ); ?></span> <?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?> </footer><!-- .entry-meta --> <?php endif; }
-
AuthorPosts
- You must be logged in to reply to this topic.