[Resolved] Custom author page

Home Forums Support Custom author page

Viewing 5 posts - 16 through 20 (of 20 total)
  • Author
    Posts
  • #1168212
    Tom
    Lead Developer
    Lead Developer

    You could try this instead:

    add_filter( 'generate_page_hero_post_author', function() {
        global $post;
        $author_id = $post->post_author;
        $url = get_author_posts_url( $author_id );
    
        if ( 1 === $author_id ) {
            $url = 'YOUR CUSTOM URL';
        }
    
        if ( 2 === $author_id ) {
            $url = 'YOUR CUSTOM URL';
        }
    
        return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>',
            esc_url( $url ),
            esc_attr( sprintf( __( 'View all posts by %s', 'gp-premium' ), get_the_author_meta( 'display_name', $author_id ) ) ),
            esc_html( get_the_author_meta( 'display_name', $author_id ) )
        );
    } );
    #1169784
    Dana

    Hey Tom. Sadly non of these options are working 100%.

    Option 1 below does work if I use the search results page and click on the author but does not work from my post pages.

    add_filter( 'author_link', function( $link, $author_id ) {
        if ( 1 === $author_id ) {
            return 'CUSTOM URL';
        }
    
        if ( 2 === $author_id ) {
            return 'CUSTOM URL';
        }
    
        return $link;
    }, 10, 2 );

    Option 2 below is the same as option 1 functionality; works from search results page but not post pages.

    add_action( 'wp', function() {
        add_filter( 'author_link', function( $link, $author_id ) {
            if ( 1 === $author_id ) {
                return 'CUSTOM URL';
            }
    
            if ( 2 === $author_id ) {
                return 'CUSTOM URL';
            }
    
            return $link;
        }, 10, 2 );
    }, 50 );

    Option 3 below doesn’t work from search results page or my post pages.

    add_filter( 'generate_page_hero_post_author', function() {
        global $post;
        $author_id = $post->post_author;
        $url = get_author_posts_url( $author_id );
    
        if ( 1 == $author_id ) {
            $url = 'CUSTOM URL';
        }
    
        if ( 2 == $author_id ) {
            $url = 'CUSTOM URL';
        }
    
        return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>',
            esc_url( $url ),
            esc_attr( sprintf( __( 'View all posts by %s', 'gp-premium' ), get_the_author_meta( 'display_name', $author_id ) ) ),
            esc_html( get_the_author_meta( 'display_name', $author_id ) )
        );
    } );

    Options 1 & 2 are close but there still seems to be an issue with the Elements Post Hero Header I’m using with the {{author}} template tag as it still points to //mywebsite.com/author/author-name from my posts pages. From the search results page, hovering/clicking on the author name points to //mywebsite.com/custom-author-page.

    #1170564
    Tom
    Lead Developer
    Lead Developer

    You need to have the first function and the last function.

    The first function will do it for your archives, while the last function will do it for the page heroes.

    The first function should do it everywhere, but if it’s not working for page heroes, that last function is necessary.

    #1171048
    Dana

    I get it now Tom. Thanks. I work on my site in the evenings and the brain is not firing on on cylinders after working all day.

    The first function works for archives no problem.

    However the third function was still returning the wrong URL. I tested the function by replacing the third parameter (author name) with the URL parameter and it printed out //mywebsite.com/author/author-name/ where the author name would normally show on the hero page and was still //mywebsite.com/author/author-name if I hovered over the the full url. This helped me troubleshoot if the function was actually working.

    So I changed the PHP operator from ‘===’ (identical) to ‘==’ (equal) and it worked giving me //mywebsite.com/custom-author-page when I hovered and clicked the author name.

    Thanks for your time and patience on this one while I brush up on my PHP chops.

    #1171825
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad you got it working! 🙂

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