Site logo

[Resolved] Replace link to Author page

Home Forums Support [Resolved] Replace link to Author page

Home Forums Support Replace link to Author page

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #2528633
    Dave

    I currently have these two snippets activated, which pull my headshot into the byline:

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_post_date_output', function( $date ) {
        printf( 
            '<span class="meta-gravatar">%s</span>',
            get_avatar( get_the_author_meta( 'ID' ) )
        );
    
        echo '<span class="meta-data">';
    
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() )
            )
        );
    
        echo $date;
    
        echo '</span>';
    } );
    function lh_page_hero_gravatar() {
        ob_start();
        global $post;
        $author_id = $post->post_author;
        ?>
        <div class="page-hero-gravatar">
            <?php echo get_avatar( $author_id ); ?>
        </div>
        <?php
        return ob_get_clean();
    }
    add_shortcode( 'page_hero_gravatar','lh_page_hero_gravatar' );
    #2529306
    David
    Staff
    Customer Support

    Hi there,

    remove the function that Ying provided.
    Then replace this:

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_post_date_output', function( $date ) {
        printf( 
            '<span class="meta-gravatar">%s</span>',
            get_avatar( get_the_author_meta( 'ID' ) )
        );
    
        echo '<span class="meta-data">';
    
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() )
            )
        );
    
        echo $date;
    
        echo '</span>';
    } );

    with:

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_post_date_output', function( $date ) {
        if ( get_the_author_meta( 'ID' ) == 1 ) {
            $author_url = 'https://www.irreverentgent.com/about-dave-bowden/';
        } else {
            $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
        }
        printf( 
            '<span class="meta-gravatar">%s</span>',
            get_avatar( get_the_author_meta( 'ID' ) )
        );
    
        echo '<span class="meta-data">';
    
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                $author_url,
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() )
            )
        );
    
        echo $date;
    
        echo '</span>';
    } );

    On this line: if ( get_the_author_meta( 'ID' ) == 1 ) { you need to change the 1 to match your user ID.

    #2529372
    Scott

    I get:

    Don't Panic
    
    The code snippet you are trying to save produced a fatal error on line 21:
    
    Unclosed '{' on line 2
    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.
    
    Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.
    #2529607
    David
    Staff
    Customer Support

    Do you have any code before that function ?

    #2529756
    Scott

    No I placed the code in a Code Snippets snippet exactly as you posted … except edited my page info for the author url and changed the ID to mine.

    #2529802
    Ying
    Staff
    Customer Support

    Hi Scott,

    I just tested David’s code, there is no error.

    Can you show the exact code you are using? Please wrap it with the code tags.

    #2529821
    Scott

    You’re right. When I copied Davids code I didn’t get all of it copied. The last 3 lines (not including the blank lines) didn’t get copied. I works just fine.

    #2529826
    Scott

    The only thing is now after this is in place My picture, name, and date are all squished side by side. But Dave’s, the original poster, idea is better than the one I was using previously.

    screenshot

    #2529876
    Dave

    The new code David provided worked for me. Thanks David and Ying!

    #2530182
    David
    Staff
    Customer Support

    Glad to hear that Dave.
    Scott if you want to raise a new topic i can take a look at your site and see what CSS is required to format that.

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