Archived topic
Social links and co-authors in author box
24 replies · Started by Álvaro on November 15, 2020
Hi!
I have add to my website this hook code, in GeneratePress elements, inspired by one found in this forum:
<div class="author-box">
<div class="avatar">
<?php echo get_avatar( get_the_author_meta('user_email'), '96', '' ); ?>
</div>
<div class="author-info">
<h5 class="author-title" itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name"><?php printf( get_the_author_meta( 'display_name') );?></span>
</h5>
<div class="author-summary">
<p class="author-description"><?php echo wp_kses( get_the_author_meta( 'description' ), null ); ?></p></div>
<div class="author-links">
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" title="Read more">...</a>
</div>
</div>
</div>
I have some posts that have two or more authors, so I want to show their boxes. Is it possible?
Another thing. Authors in my website have their social media links. Is it possible to show adding some code?
I don't want to use a plugin, just code in the hook.
Thanks! I'm very excited with Generate Press :)
Hi there,
co-authors and social links are not part of WordPress core, adding that functionality would require another plugin or custom function. So unfortunately this kind of function would require custom development or a plugin.
I would recommend looking for a plugin to do this, as code is code whether it be in a plugin or custom developed. The advantage of a plugin is you have developer support that will maintain the code for any updates WP makes.
Simple Author Box provides author social links:
https://en-gb.wordpress.org/plugins/simple-author-box/
It does also provide co-authors as part of their premium plugin.
Hi, David.
Thanks. I excepted maybe is possible to add co-authors. I've seen in this forum this code from Tom (as I remember):
add_filter( 'generate_post_author_output', 'tu_co_author_plus' );
function tu_co_author_plus( $author ) {
if ( function_exists( 'coauthors_posts_links' ) ) {
return ' Por ' . coauthors_posts_links( null, null, null, null, false );
}
return $author;
It helps to show co-authors names below title. Maybe it's possible to add this function to the code I provided above.
Thanks!
Edit: the code was yours! :)
Hi there,
With co authors plus, you may be able to replace this:
<span itemprop="name"><?php printf( get_the_author_meta( 'display_name') );?></span>
With this:
<?php
if ( function_exists( 'coauthors_posts_links' ) ) {
echo 'Por ' . coauthors_posts_links( null, null, null, null, false );
}
?>
Ah, you're wanting to display two completely different author boxes?
In that case, you would need a way to get all authors of the post (a function), then we'd need to loop your original code and replace the internals with the data from the function.
Not sure of co authors plus allows for this?
Hi, Tom. Yes, this is what I had with my previous theme, Herald (by Meks). Their plugin (Meks Smart Author Widget) also allows to show more than one box, but it has a terrible viewing in themes that are not by Meks. Maybe you can see their code, because it's a thing that is allowed by co-authors plus.
Thanks, Tom. You and you're team are amazing and good partners!!
Unfortunately, I'm not able to dig into other plugin code at the moment.
However, if you'd like to set it up on your site, we can see if we can make it display nicer with some CSS.
Thank you, Tom. Maybe it's interesting to have one code for this in the future.
I've activated the Meks plugin, so you can see here, for example, an article with two authors: https://descubrirlahistoria.es/2020/10/obreros-y-estudiantes-contra-el-franquismo-2a-parte-crisis-final-del-regimen-y-transicion/
The problems I see is the image position (maybe it'll be better aligned left to the text), space margin on the top, and font size (I think is too big).
Thanks again, Tom!
Something like this may help:
.mks-co-authors-wrapper > a {
float: left;
margin-right: 1.5em;
}
.mks-co-authors-wrapper {
padding: 20px;
background: #fafafa;
margin: 15px 0;
font-size: 15px;
}
Wow, amazing Tom. It's very nice. Thank you very much for your useful help.
You're welcome! :)
Hi Tom,
I am looking to to do the same in my blog and I just wanted to double check with you where to insert the codes mentioned above.
Looking forward to your response.
Regards,
Stefan
Just to add, I am not sure what are the prerequisites in terms of the plugins and also where to insert the following codes:
Plugins: do I need to have both:
- co-authors plus: https://wordpress.org/support/plugin/co-authors-plus/
- meks smart author widge: https://wordpress.org/plugins/meks-smart-author-widget/
Codes: (whether I should add) and where to do so for the following codes:
1)
add_filter( 'generate_post_author_output', 'tu_co_author_plus' );
function tu_co_author_plus( $author ) {
if ( function_exists( 'coauthors_posts_links' ) ) {
return ' Por ' . coauthors_posts_links( null, null, null, null, false );
}
return $author;
2)
<?php
if ( function_exists( 'coauthors_posts_links' ) ) {
echo 'Por ' . coauthors_posts_links( null, null, null, null, false );
}
?>
Visuals: I already have the CSS code for the way I would like to author box to look. It's like the one at the bottom of this link: https://www.lifestyledemocracy.com/how-is-the-revolution-will-not-be-televised-poem-relevant-today-2-2/. What I am missing is the ability to show the second (third and so forth authors) as well as their respective author boxes.
Looking forward to your response.