Archived topic
removing the word "by" on blog but keep author name
9 replies · Started by Streater on July 16, 2021
I searched all over for this one but no one seems to have the same problem... everyone else wants to remove the author name.
On my Blog/Newsroom/(is_home) I want to remove the word "by" next to the author... but keep the author name. I added an icon before the Author so now it says: "By (icon) (author)". You can see it on the link below.
I don't have this problem on the actual posts as I used the meta {{post_author}} which does not include the word by.
Thanks!
Hi there,
Give this function a shot:
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
if ( 'author' === $item ) {
$output = '';
}
return $output;
}, 10, 2 );
Let us know :)
Didn't work. All caching is turned off too by the way.
Hi there,
are you using any other functions to change the post meta?
Maybe... These are functions I am using for author:
<?php
add_filter( 'generate_page_hero_post_author', function() {
global $post;
$author_id = $post->post_author;
return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><span class="author-name" itemprop="name">%s</span></span>',
esc_html( get_the_author_meta( 'display_name', $author_id ) )
);
} );
?>
<?php
add_filter( 'generate_post_author_output', function() {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
__( 'by','generatepress'),
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() )
)
);
} );
?>
<?php
add_filter( 'wpsp_author_output', 'tu_wpsp_remove_author_link' );
function tu_wpsp_remove_author_link() {
printf(
'<span class="wp-show-posts-byline wp-show-posts-meta">
<span class="wp-show-posts-author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">
<span class="author-name" itemprop="name">%1$s</span>
</span>
</span>',
esc_html( get_the_author() )
);
}
?>
<?php
/////////////REMOVE AUTHOR FROM CAREERS///////////////
add_action( 'wp', function() {
if ( has_category( array( 6 ) ) ) {
add_filter( 'generate_post_author', '__return_false' );
}
} );
?>
Edit this section:
add_filter( 'generate_post_author_output', function() {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
__( 'by','generatepress'),
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() )
)
);
} );
to this:
add_filter( 'generate_post_author_output', function() {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
__( '','generatepress'),
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() )
)
);
} );
Omg makes total sense and it worked. I was even added in a | divider to make it look better. Thanks!
No problem :)
Just to mention that there's a much easier way to do this now with the help of dynamic content and block element:
https://docs.generatepress.com/article/block-element-post-meta-template/
Oh wow good to know... thanks!
No problem :)