Archived topic
Need to take away auyhor link
9 replies · Started by Jacob on March 30, 2022
Hi, a long time ago leo helped me with some really useful codes in order to place an author image + name on my pages.
How can I take away the link from the author page and just keep my name there? Thanks! (You see the author under the H1 Header)
I use the snippet plugin and have these codes added:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_post_date_output', function( $date ) {
printf(
'<span class="meta-gravatar">%s</span>',
get_avatar( get_the_author_meta( 'ID' ) )
);
echo '<span class="meta-data">';
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><span class="author-name" itemprop="name">%3$s</span></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
echo $date;
echo '</span>';
} );
and CSS
add_action( 'wp_head', function () { ?>
<style>
.entry-meta, .entry-meta .meta-data {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.entry-meta .meta-data {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
margin-left: 0.75em;
}
.entry-meta .meta-gravatar img {
width: 40px;
border-radius: 50%;
}
.byline {
font-weight: 700;
}
.entry-meta .meta-data .posted-on {
font-size: 0.8em;
}
</style>
<?php } );
Ans also this one:
add_action( 'generate_after_entry_header', 'tu_page_meta' );
function tu_page_meta() {
if ( 'page' == get_post_type() ) : ?>
<!-- .entry-meta -->
<?php endif;
}
To be clear - I mean take away the link from the Author-name :) Thanks!
Hi Jacob,
Try change this line: esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ) tto ''.
Let me know!
Hi ying!
Thanks! That changed something. However I can still see thar the Author howers when I have the mouse on the name. When i click on it i get directed to the homepage. I need to completley change it to just plain text (or no link).
Do you have any idea how to diable it? Thanks!
Best,
Jacob
Well I took a closer look to your code, if the code is running correctly, you should not need to change the esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), as your code outputs NO link to the author name.
It looks to me your PHP code is not running.
Try this:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_post_date_output', function( $date ) {
printf(
'<span class="meta-gravatar">%s</span>',
get_avatar( get_the_author_meta( 'ID' ) )
);
echo '<span class="meta-data">';
printf( ' <span class="byline">%1$s',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><span class="author-names" itemprop="name">%3$s</span></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
echo $date;
echo '</span>';
} );
Thanks! It works fine now!! 1 thing however, the format on the date is abit screwed up, it is written in one string with the author: "Webmastermai 1, 2020" except on the homepage where it looks ok.
Sorry, the homepage author box also looks bad.
Do you want something like this?
https://www.screencast.com/t/RBU4xnu5W
If so, add this CSS:
.entry-meta span.byline {
display: flex;
flex-direction: column;
}
Thanks so much Ying! It worked! amazing!
Best,
Jacob
You are welcome :)