0

Live link: http://beertournament.com/

Type in YYYYY in source code to see relevant section of source code. If you hover over "Tree House" on the live site, you should one url but if you look in the source code, you should see a different url.

1st thought is that front page is cached but I don't have a live cache plugin at the moment.

Here is the code section if that helps:

`<?php if ( !is_page() ) :
        $author_posts_url = the_author_link();
            $posts_by_title   = sprintf(
            __( 'Posts by %1$s ( @%2$s )', 'p2-breathe' ),
            get_the_author_meta( 'display_name' ),
            get_the_author_meta( 'user_nicename' )
        ); ?>
    <a href="<?php echo esc_url( $author_posts_url ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="author-avatar">
        <?php echo get_avatar( $author_posts_url ); ?>
    </a>
    <?php endif; ?>

    <div class="entry-meta">
        <?php if ( ! is_page() ) : ?>
            <a href="<?php echo esc_url( the_author_link() ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="entry-author"><?php the_author(); ?></a>
        <?php endif; ?>
        <span class="entry-date">`

Updated with screenshot links in comments.

Update 1: Updated to this code....

<?php if ( !is_page() ) :
            $author_posts_url = the_author_link();
        $posts_by_title   = sprintf(
        __( 'Posts by %1$s ( @%2$s )', 'p2-breathe' ),
        get_the_author_meta( 'display_name' ),
        get_the_author_meta( 'user_nicename' )
    ); ?>
<a href="<?php echo esc_url( $author_posts_url ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="author-avatar">
    <?php echo get_avatar( $author_posts_url ); ?>
</a>
<?php endif; ?>

<div class="entry-meta">
    <?php if ( ! is_page() ) : ?>
        <a href="<?php echo get_author_posts_url(the_author_ID()); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="entry-author"><?php the_author(); ?></a>
    <?php endif; ?>
    <span class="entry-date">

Update 2 - here is the content.php code: http://pastebin.com/QHH24ha2

3

1 Answer 1

2
+50

You are echoing the author link generator inside an already opened anchor tag, which is causing error. Try this code:

Method 1

<?php if ( !is_page() ) :
        $author_posts_url = the_author_link();
            $posts_by_title   = sprintf(
            __( 'Posts by %1$s ( @%2$s )', 'p2-breathe' ),
            get_the_author_meta( 'display_name' ),
            get_the_author_meta( 'user_nicename' )
        ); ?>
    <a href="<?php echo esc_url( $author_posts_url ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="author-avatar">
        <?php echo get_avatar( $author_posts_url ); ?>
    </a>
    <?php endif; ?>

    <div class="entry-meta">
        <?php if ( ! is_page() ) : ?>
            <a href="<?php echo get_author_posts_url(); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="entry-author"><?php the_author(); ?></a>
        <?php endif; ?>
        <span class="entry-date">

Noticed that i replaced echo esc_url( the_author_link() ); with get_author_posts_url() which will only return the URL, not a full anchor.

You may also want to use get_author_posts_url(the_author_ID()) if the code didn't work at the first place.

Method 2

If you are not running this code in a loop and don't have access to the author ID, you can change the following line:

<a href="<?php echo esc_url( the_author_link() ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="entry-author"><?php the_author(); ?></a>

to:

<?php the_author_link(); ?>

Which will still return a link to author page, but without class="entry-author" which i don't think would be a great deal since you can tweak your css to achieve the same result.

5
  • If you see my updated code (I edited original post), that is what I put in there now onto live site.
    – Adam
    Commented Jan 21, 2017 at 1:15
  • We're in the loop. Here is full content.php: pastebin.com/QHH24ha2
    – Adam
    Commented Jan 21, 2017 at 1:26
  • I investigated your source code while you were testing method 1 and noticed everything is correct. The only reason the link is altered in live page can be a script. I noticed you have a plugin called O2 which is probably injecting the URL in your author link at around line 1015 of your source code. Try disabling the plugin and see if it works.
    – Johansson
    Commented Jan 21, 2017 at 1:28
  • Ah I see you are correct. Disabling the plugin yielded the desired result but took out too much functionality so I'll have to keep that link and see if I can change that meta section at all using the child theme code. Thanks.
    – Adam
    Commented Jan 21, 2017 at 1:37
  • Let us continue this discussion in chat.
    – Adam
    Commented Jan 21, 2017 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.