Author name link to author page using essential grid

Hello,

I have found these instructions, which work, but i want to use simple the author name, rather than the avatar, that has the same link.

https://www.themepunch.com/faq/author-avatars-essential-grids/

Can you help me with the correct code?

Thanks

Hi There,

You can try with this code:

/* [essential_author author='%author_name%' size='54' link='yes']
 */
function essential_author( $atts ) {
 
    extract( shortcode_atts( array (
 
        'author' => 'admin',
        'size'   => '54',
        'link'   => ''
 
    ), $atts ) );
 
    global $wpdb;
    $user = $wpdb->get_results( "SELECT ID FROM $wpdb->users WHERE display_name = '$author'" );
 
    $author_id     = $user[0]->ID;
    $author_link   = get_author_posts_url( $author_id );
 
    $html = '';
    if( $link === 'yes' ) $html .= '<a href="' . $author_link . '" title="' . $author . '">';
 
    $html .= $author;
    if( $link === 'yes' ) $html .= '</a>';
 
    return $html;
 
}
 
add_shortcode( 'essential_author', 'essential_author' );

Let us know how it goes!

perfect thank you!

I also have a different but related need:

I would like the author name in my blog posts to be a link and link to the same author page as the essential grid code you just made for me?

Is that possible at all?

Many thanks,

Sophie

Hi There,

Thanks again for asking!

To add the link to the author, please add the following code under functions.php file locates in your child theme:

function x_integrity_entry_meta() {

    //
    // Author.
    //

    $author = sprintf( '<span><i class="x-icon-pencil" data-x-icon="&#xf040;"></i> <a href="%s">%s</a></span>',
      get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ),
      get_the_author()
    );


    //
    // Date.
    //

    $date = sprintf( '<span><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar" data-x-icon="&#xf073;"></i> %2$s</time></span>',
      esc_attr( get_the_date( 'c' ) ),
      esc_html( get_the_date() )
    );


    //
    // Categories.
    //

    if ( get_post_type() == 'x-portfolio' ) {
      if ( has_term( '', 'portfolio-category', NULL ) ) {
        $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
        $separator         = ', ';
        $categories_output = '';
        foreach ( $categories as $category ) {
          $categories_output .= '<a href="'
                              . get_term_link( $category->slug, 'portfolio-category' )
                              . '" title="'
                              . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                              . '"><i class="x-icon-bookmark" data-x-icon="&#xf02e;"></i> '
                              . $category->name
                              . '</a>'
                              . $separator;
        }

        $categories_list = sprintf( '<span>%s</span>',
          trim( $categories_output, $separator )
        );
      } else {
        $categories_list = '';
      }
    } else {
      $categories        = get_the_category();
      $separator         = ', ';
      $categories_output = '';
      foreach ( $categories as $category ) {
        $categories_output .= '<a href="'
                            . get_category_link( $category->term_id )
                            . '" title="'
                            . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                            . '"><i class="x-icon-bookmark" data-x-icon="&#xf02e;"></i> '
                            . $category->name
                            . '</a>'
                            . $separator;
      }

      $categories_list = sprintf( '<span>%s</span>',
        trim( $categories_output, $separator )
      );
    }


    //
    // Comments link.
    //

    if ( comments_open() ) {

      $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
      $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
      $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );

	  $text = ( 0 === $number ) ? 'Leave a Comment' : sprintf( _n( '%s Comment', '%s Comments', $number, '__x__' ), $number );

$comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments" data-x-icon="&#xf086;"></i> %3$s</a></span>',
        esc_url( $link ),
        esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
        $text
      );

    } else {

      $comments = '';

    }


    //
    // Output.
    //

    if ( x_does_not_need_entry_meta() ) {
      return;
    } else {
      printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
        $author,
        $date,
        $categories_list,
        $comments
      );
    }

}
 

Hope this helps!

Thanks

1 Like

Perfect again - thanks so much!

On behalf of my colleague, you’re welcome. Cheers! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.