- This topic has 10 replies, 3 voices, and was last updated 1 year, 3 months ago by David.
June 24, 2019 at 7:59 pm #940091Clayton
Is it possible to allow template tags to work within hooks? I’ve run into this several times where it would be super helpful if template tags worked within hooks…not just headers. The main issue I’m having though is that I’m trying to simply display the author name but can’t get it to display within the above content hook.
This is the code I’m using that isn’t working. I’ve got the avatar and date showing but can’t get the author name to display.
<?php get_the_author_meta( 'display_name', $author_id ); ?>
Any help would be greatly appreciated.June 25, 2019 at 2:49 am #940310DavidStaffCustomer Support
not currently, as i am not sure it is possible to add the template tags to hooks.
So the function needs to be echoed out like this:
<?php echo get_the_author_meta('display_name', $author_id); ?>
This will just output the string. So i you want to give it some style then do this instead:
<?php $custom_author_name = get_the_author_meta('display_name', $author_id); echo '<span class="custom-author">' . $custom_author_name . '</span>'; ?>June 25, 2019 at 5:22 am #940443Clayton
Thanks for the reply David. That still doesn’t seem to be working. Here is a screenshot of what I have. https://imgur.com/a/usZfAZHJune 25, 2019 at 5:38 am #940459DavidStaffCustomer SupportJune 25, 2019 at 5:42 am #940462Clayton
Weird. Still nothing…man this is so strange. It’s a very clean install of WordPress too so I don’t think there is anything conflicting.June 25, 2019 at 5:56 am #940485DavidStaffCustomer SupportJune 25, 2019 at 6:05 am #940493Clayton
Good thing to check: https://imgur.com/a/T2JVd1l
I think that is right…June 25, 2019 at 10:44 am #940902Clayton
Any other thoughts on what my causing the issue here? Let me know if you need login to take a look.June 25, 2019 at 3:49 pm #941127TomLead DeveloperLead Developer
You have a couple of issues there.
$author_idaren’t defined anywhere.
get_avatar()should look like this:
Then you should remove
$author_idfrom the other
get_the_author_meta()function.June 26, 2019 at 7:54 am #941943Clayton
This seems to be working from me. If you guys seen any red flags let me know.
<?php global $post; $author_id=$post->post_author; ?> <div class="custom-post-sub-heading"> <h2><?php single_post_title(); ?></h2> <h4><?php the_excerpt(); ?></h4> <div class="custom-post-meta"> <div class="post-avatar"><?php echo get_avatar( $author_id, $size = '70'); ?></div> <span class="author-name"><a href="<?php echo get_author_posts_url($author_id); ?>"><?php the_author_meta( 'display_name', $author_id ); ?></a></span><br> <span class="entry-date"><?php echo get_the_date(); ?></span> <span class="read-time">[kt_reading_time]</span> </div> </div>June 26, 2019 at 8:02 am #941960
- You must be logged in to reply to this topic.