[Support request] Author name at bottom of article

Home Forums Support [Support request] Author name at bottom of article

Home Forums Support Author name at bottom of article

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #912962
    Emma

    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.

    #913028
    David
    Staff
    Customer Support

    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.

    #913041
    Emma

    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?

    #913105
    David
    Staff
    Customer Support

    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

    #913145
    Emma

    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?

    #913160
    David
    Staff
    Customer Support

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

    #913622
    Emma

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

    #913797
    Tom
    Lead Developer
    Lead Developer

    If you’re able to try 2.3 (currently in alpha), we can try the new post meta ordering system?: https://generatepress.com/generatepress-2-3/

    Let me know πŸ™‚

    #915134
    Emma

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

    #915458
    Tom
    Lead Developer
    Lead Developer

    Cool – let me know if you install it and I’ll provide the code πŸ™‚

    #936642
    Emma

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

    #937141
    Tom
    Lead Developer
    Lead Developer

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

    #943590
    Emma

    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

    #944137
    Tom
    Lead Developer
    Lead Developer

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

    #947555
    Curt

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

    Thanks.

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