Archived topic
Adding author to pages
7 replies · Started by gedosan on February 27, 2018
Hi - was wondering if there's a way to add the author byline to pages rather than just posts?
I tried adding {{post_author}} as a GP hook but it didn't work. Just want it to appear below the page title.
Thanks
G
Hi there,
Give this function a shot:
add_action( 'generate_after_entry_header', 'tu_page_meta' );
function tu_page_meta() {
if ( 'page' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif;
}
Let me know :)
Cheers. Added it as a GP hook but didn't work. So tried it as a snippet, still no joy. Am i doing something wrong?!
Cheers
Snippet is the right way to do it.
I just tweaked the code above so it should work now :)
Cheers, it's cool (and working) but it's appearing on some page (e.g. the homepage) where I don't want it to. Is there an easy way to exclude certain pages?
Thanks
You could do this:
add_action( 'generate_after_entry_header', 'tu_page_meta' );
function tu_page_meta() {
if ( 'page' == get_post_type() && ! is_page( array( 10, 15, 20 ) ) ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif;
}
10, 15 and 20 being the IDs of the pages you want to exclude.
Works a treat - the best support again, awesome thanks.
You're welcome :)