Archived topic
Meta Style Question
14 replies · Started by Chris on December 22, 2019
1. First, I've read this article: https://docs.generatepress.com/article/entry-meta-style/. When it says 'add this PHP snippet': http://prntscr.com/qeehh3, does that mean I apply the code inside 'Custom CSS'
2. I'd like my byline underneath the title to read like this:
By Name | Date
Hi there,
1. Adding PHP: https://docs.generatepress.com/article/adding-php/
2. Let's try the snippet in the doc article first.
So do I just copy this code:
add_filter( 'generate_post_author_output', function() {
return sprintf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></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() ),
get_avatar( get_the_author_meta( 'ID' ) )
)
);
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'comments-link',
'date',
);
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array(
'date',
'categories',
);
} );
And paste it at the end of function.php like this: http://prntscr.com/qeeqez
If so, could you modify the code where the end result looks like this:
By: Name | Date
To do that, try this:
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
);
} );
add_filter( 'generate_inside_post_meta_item_output', function( $output, $type ) {
if ( 'author' === $type ) {
$output = 'By: ';
}
if ( 'date' === $type ) {
$output = ' | ';
}
return $output;
}, 10, 2 );
Let me know :)
Hey Tom,
I pasted your code and now my site (more specifically, blog posts) are receiving this error:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /home/customer/www/test.com/public_html/wp-includes/class-wp-hook.php on line 290 and exactly 2 expected in
Sorry about that - can you try now?
No worries :) That worked! How could I remove the links from author and date?
For example, it says "by [name] | [date]"
The name links to my author bio. And the date links to the post.
How could I remove both links?
The 'Remove Link' from Author byline worked.
However, when I add the code to remove link from date:
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
printf( '<span class="posted-on">%s</span>',
$time_string
);
}, 10, 2 );
it removes the separator between name and date. For example:
Original: by Name | Date
After removing link from date: by namedate
Hi there,
you can edit this part of the code:
<span class="posted-on">%s</span> to include the extra content eg.
<span class="posted-on"> | %s</span>
That worked! Thanks David :)
However, I came across another issue:
Whenever I update the post, the date remains the same as the original publish date.
For example, I published an article yesterday (December 23, 2019). Today, I modified the article and clicked "Update".
When I view the post, the date still shows as December 23, 2019. Instead, it should've updated with December 24, 2019.
Hi there,
Have you set it up so the updated date displays?: https://docs.generatepress.com/article/show-the-updated-post-date/
Perfect, thank you!
Awesome support from Leo, David, and Tom! Thanks a bunch guys!!
Glad we could help :)