Site logo

Archived topic

Author name at bottom of article

15 replies · Started by Emma on May 28, 2019

Viewing posts 1–15 of 16

Hi,

I'd like to know if there is a way to have the author name at the bottom of each article instead of at the top?

Thanks.

Hi there,

we could use a hook to add that in - which is what i did here to add the author box:

https://gpsites.co/volume/sample-post/

Let me know if thats something you would like or just the author name.

Thanks, I'm just looking to move the author name so it just says 'by name' at the bottom of the post instead of at the top if that's possible?

So create a new Hook Element:

https://docs.generatepress.com/article/hooks-element-overview/

Give it a title and add this content:

<span class="author-name" itemprop="name"><?php printf( esc_attr__( 'by %s', 'the author' ), get_the_author_meta( 'display_name') );?></span>

Select the after_content hook.
Check execute PHP
Set the priority to 0
Then set the display rules to Posts > All Posts

Ok, thank you, will try this. Is there a way to do it by just adding some php code without using hooks? I managed to move the categories on the post archives with some code that I copied and pasted (I use the code snippets plugin)... Is that possible at all rather than using a hook or is that the only way to do it?

Its more complicated, but yes you can use the add_action function:

https://docs.generatepress.com/article/using-hooks/#usage

With a conditional tag to specify the single post:

https://docs.generatepress.com/article/using-hooks-conditional-tags/#single-posts

So your code would look something like this:

add_action( 'generate_after_content','db_after_post_author' );  
function db_after_post_author() { 
    if ( is_single() ) : ?>
        <span class="author-name" itemprop="name"><?php printf( esc_attr__( 'by %s', 'the author' ), get_the_author_meta( 'display_name') );?></span>
    <?php endif;
}

The Hook Element is so less messy :)

This doesn't seem to work, I will try it the other way with the hook. Thanks

Yes, I would be interested in trying it. I should be very simple what I want to do as I just want the author name at the bottom of the post :)

Cool - let me know if you install it and I'll provide the code :)

I have the latest version installed now and I would like the code to do this. Thanks.

Let's try this:

add_filter( 'generate_header_entry_meta_items', function( $items ) {
    return array_diff( $items, [ 'author' ] );
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    $items[] = 'author';

    return $items;
} );

Let me know :)

Thanks for this, works great. It is possible for the author to go above the category? At the moment it is at the bottom of the post but it is in between the category and the post navigation... Thanks

Definitely, replace the second filter above with this one:

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    array_unshift( $items, 'author' );

    return $items;
} );

Let me know :)

Hi Tom,
Sorry, I'm not well versed in code. Where is that you actually install that snippet you posted above?

Thanks.

This archived topic is closed to new replies.