Black Friday sale! Get up to 25% off GP Premium! Learn more ➝

[Resolved] Elements – Author PHP won't display

Home Forums Support [Resolved] Elements – Author PHP won't display

Home Forums Support Elements – Author PHP won't display

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #1035542
    <p>This post was written by <?php the_author(); ?> - The Author.</p>
    <?php echo get_avatar( get_the_author_meta( 'ID' ));?>

    I can’t figure out why I can’t get an output. Neither of those will work. I’m just trying to display the author name so that I can style it.
    Displaying other post data (title, meta, etc) work just fine.
    I’m sure I’m missing something obvious.

    The above first line just outputs as:

    “This post was written by – The Author.”

    The second line just outs the default avatar.

    I’m using the ‘HOOK’ element. I have ensured that “Execute PHP” is checked.
    I’m using a modified version of the ‘Merch’ template.

    Thanks for any info!

    Customer Support

    Hi there,

    which Hook are you using ?



    Was attempting various. I want it to display ‘after_header’ – and I was just adding to the “Single Post Entry Header” element that is added by the Merch template. That template already displays the title, categories, date.

    Seems to only work if the HOOK selected is after_main_content or later?

    Customer Support

    Yeah those functions only work within the loop or inside the post content. Try this instead:

    global $post; 
    $author_name = get_the_author_meta( 'display_name', $author_id );
    $author_avatar = get_avatar( $author_id, 50 ); 
    printf( '<span class="hero-byline">This post was written by %1s</span><span class="hero-avatar">%2s</span>',

    Yes! the layout here was throwing me for a …loop.

    On a (related) note, a slight typo on the doc for ‘removing author’ from a page in the Documentation:

    It should say “Another example is if you want to remove the AUTHOR on a specific post type, but keep it elsewhere”

    Customer Support

    Glad to be of help – and thanks for pointing out the typo! We’ll get that fixed asap

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