[Resolved] Adding author to pages

Home Forums Support [Resolved] Adding author to pages

Home Forums Support Adding author to pages

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #506994
    gedosan

    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

    #507493
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #507589
    gedosan

    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

    #508124
    Tom
    Lead Developer
    Lead Developer

    Snippet is the right way to do it.

    I just tweaked the code above so it should work now πŸ™‚

    #508357
    gedosan

    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

    #508550
    Tom
    Lead Developer
    Lead Developer

    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.

    #509140
    gedosan

    Works a treat – the best support again, awesome thanks.

    #509372
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.