Archived topic
Editing the entry meta output
16 replies · Started by Brian on April 15, 2020
Hi
I need to edit my entry meta to move the comments link so that it sits on the end of the line.
I've searched the forum and found some code for modifying the meta, and here's what I'm using to edit it so far.
The code snippet
add_filter( 'generate_post_date_output', 'lh_single_comments_link' );
function lh_single_comments_link( $date ) {
echo $date;
if ( is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
echo '</span>';
}
}
And this CSS to show the comment link, plus change the post to 'Last Updated:'
.single .comments-link {
display: inline-block;
}
.posted-on .updated {
display: inline-block;
}
.posted-on .updated + .entry-date {
display: none;
}
.posted-on .updated:before {
content: "Last Updated: ";
}
Hi there,
Try this, instead:
add_filter( 'generate_header_entry_meta_items', function( $items ) {
$items[] = 'comments-link';
return $items;
} );
Let me know :)
Still the same :(
Hi Tom,
I changed the snippet to that code, but that it seems to eliminate the comment link altogether.
Is the comments count option enabled in Customize > Layout > Blog?
No, it wasn't. I enabled it and the comment link now works now.
I thought that was just to show the link on archives which I'm not sure I want, but I can live with.
Thanks for the help Tom :)
You could try this:
body:not(.single) .comments-link {
display: none;
}
Hey Tom
That worked, thanks so much!
You're welcome :)
Hi Tom
The code to show a comment link seems to have stopped working, here's what I have in place.
Snippet
add_filter( 'generate_header_entry_meta_items', function( $items ) {
$items[] = 'comments-link';
return $items;
} );
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
printf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );
CSS
.single .comments-link {
display: inline-block;
}
.posted-on .updated {
display: inline-block;
}
.posted-on .updated + .entry-date {
display: none;
}
.posted-on .updated:before {
content: "Last Updated: ";
}
body:not(.single) .comments-link {
display: none;
}
Any chance you can link us to the page/post in question?
The link in the original topic is no longer working.
Let me know :)
Hi Leo, here's a link
https://www.savvyhomemade.com/bath-bomb-recipe/
Hi there,
Try adding this:
add_action( 'wp', function() {
if ( is_single() ) {
add_filter( 'generate_show_comments', '__return_true' );
}
} );
Hi Tom
That worked, thanks!
Any idea how to style it to separate it from the author's name, perhaps with a verticle bar before?
by Author | 29 Comments | This post contains affiliate links,
Brian
Hi there,
add this CSS:
.entry-meta .comments-link:before {
content: '| ';
}