- This topic has 15 replies, 3 voices, and was last updated 3 years, 11 months ago by David.
-
AuthorPosts
-
April 28, 2020 at 6:29 pm #1260478ben2619
How do I add the post category beside the post date and the name of the poster. Currently it reads like this:
THIS IS THE TITLE OF THE POST
April 29, 2020 by Writer’s Name.I want it to look like this:
THIS IS THE TITLE OF THE POST
April 29, 2020 by Writer’s Name. Posted in Post Category.Currently, when I add the post category via the customizer, it only appears at the end of the post. I’m okay with maintaining that at the bottom but I would like the category to also appear below the title and beside the date/name.
Thanks a lot. I am using the Marketer theme, by the way.
April 29, 2020 at 8:35 am #1261437LeoStaffCustomer SupportHi there,
You can try these two filters to tweak the meta that shows up on top and bottom:
https://docs.generatepress.com/article/generate_header_entry_meta_items/
https://docs.generatepress.com/article/generate_footer_entry_meta_items/Let me know if this helps 🙂
April 29, 2020 at 9:59 am #1261601ben2619Thank you. It works great. I used this code:
add_filter( ‘generate_header_entry_meta_items’, function() {
return array(
‘categories’,
‘date’,
‘author’,
);
} );Now, where do I add the text “Posted in: Category” in the above code?
Thanks again.
April 29, 2020 at 11:20 am #1261724LeoStaffCustomer SupportApril 29, 2020 at 12:51 pm #1261832ben2619I added the code on the suggested link as a snippet (using Code Snippets) but it does not seem to work. Am I missing something?
Apologies, I’m not familiar with snippets and PHP at all. Thanks.
April 29, 2020 at 1:05 pm #1261850LeoStaffCustomer SupportTry this instead:
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) { if ( 'categories' === $item ) { return ' Published in '; } return $output; }, 50, 2 );
April 29, 2020 at 1:57 pm #1261907ben2619Thank you. You’re a blessing. Now, how do I add a period or a comma after the author’s name.
It currently reads like this: April 29, 2020 by Writer’s Name Published in Post Category.
And I want it to look like thhis: April 29, 2020 by Writer’s Name. Published in Post Category.
April 29, 2020 at 2:02 pm #1261911LeoStaffCustomer SupportYou should be able to use the same filter above like this:
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) { if ( 'categories' === $item ) { return '. Published in '; } return $output; }, 50, 2 );
April 29, 2020 at 2:35 pm #1261945ben2619Thanks. I should have mentioned that I tried doing this already. The problem is, there’s a space after the author’s name like this:
POST DATE by NAME . Published in Category
which looks off and a bit unprofessional so I want it to look like this:
POST DATE by NAME. Published in Category.
Thanks again. Apologies if it looks like I’m bothered by little things (like a simple space) but I promise to be less of a bother in the future 🙂
April 29, 2020 at 3:33 pm #1262005LeoStaffCustomer SupportCan you add the code so I can see the issue?
It looks like the default setting right now.
This kind of support is within our support scope so no problem at all 🙂
April 29, 2020 at 6:56 pm #1262201ben2619Thanks a lot!
This is the code you suggested and which I also did earlier (by adding a period after return and before Published in).
add_filter( ‘generate_inside_post_meta_item_output’, function( $output, $item ) {
if ( ‘categories’ === $item ) {
return ‘. Published in ‘;
}
return $output;
}, 50, 2 );The above code results in something like the attached image. Now, my hope is to:
1) remove the space after the name and
2) at the bottom part, remove the period before the categoryHere’s the link to the image: Sample page.
April 29, 2020 at 8:01 pm #1262258LeoStaffCustomer SupportIf you remove the space in the space in the actual snippet then it should work:
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) { if ( 'categories' === $item ) { return '.Published in '; } return $output; }, 50, 2 );
Do you actually want the category to show in on top and bottom?
April 29, 2020 at 10:54 pm #1262338ben2619Thank you. I can’t seem to resolve the issue so I decided to do it via another way by replicating the code you suggested into something like this:
add_filter( ‘generate_inside_post_meta_item_output’, function( $output, $item ) {
if ( ‘categories’ === $item ) {
return ‘Published in ‘;
}
return $output;
}, 50, 2 );add_filter( ‘generate_inside_post_meta_item_output’, function( $output, $item ) {
if ( ‘date’ === $item ) {
return ‘on ‘;
}
return $output;
}, 50, 2 );add_filter( ‘generate_inside_post_meta_item_output’, function( $output, $item ) {
if ( ‘author’ === $item ) {
return ‘by ‘;
}
return $output;
}, 50, 2 );Now is there a way to simplify this code so I don’t have to add filter three times?
Thanks again.
April 30, 2020 at 5:54 am #1262882DavidStaffCustomer SupportLeo provides an example here where multiple items are set in a single filter:
April 30, 2020 at 7:28 am #1263075ben2619Works great! Thank you.
-
AuthorPosts
- You must be logged in to reply to this topic.