- This topic has 11 replies, 3 voices, and was last updated 3 years, 12 months ago by David.
-
AuthorPosts
-
March 28, 2020 at 9:13 am #1213183fellows2020
Hello,
I would like to display meta data directly below single post titles in the format of “by [author] | [month, day, year] | This post may contain affiliate links. Learn more. [where Learn more is linked to my disclosures page.]
It appears there is a way to do this via hooks (after_entry_title), but I’m just having trouble figuring it out. Could you walk me through the steps?
Thanks very much.
March 28, 2020 at 2:41 pm #1213458LeoStaffCustomer SupportHi there,
Add this PHP snippet first:
add_filter( 'generate_header_entry_meta_items', function() { return array( 'author', 'date' ); } ); add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) { if ( 'date' === $item ) { return ' | '; } return $output; }, 50, 2 );
Then create a hook element with this as your content:
<div class="affiliate">affliate content here</div>
Choose the
after_entry_title
hook then display to Post > All Posts.Let me know when this is done and I can provide some CSS ๐
March 28, 2020 at 4:02 pm #1213505fellows2020This is great. Thanks for your help so far. Almost there. Single posts now display the following:
by [author] | [date]
[affiliate content.]Could you please let me know:
1. How to put the [affiliate content] on the same line as the “by [author] | [date]
2. How to add a divider (|) after the date and before the [affiliate content]
3. How to make the font size for the [affiliate content] the same as the author and date meta data. (Right now, the affiliate content metadata font size is larger.)Thank you!
March 28, 2020 at 6:18 pm #1213545LeoStaffCustomer SupportAdd this CSS:
.entry-meta, .affiliate { display: inline-block; } .affiliate { font-size: 85%; } .affiliate:before { content: " | "; }
March 28, 2020 at 7:07 pm #1213567fellows2020Hi, One last thing: On the homepage (which shows a list of my most recent posts), the only meta data I am displaying is the date. With the changes you suggested above, there is now a ” | ” preceding the date. Could you let me know how to remove that from the display on the homepage, while keeping the format on single posts? (I edited the link in my initial ticket to send you to the homepage.) Otherwise, it looks great. Thanks for all of your help.
March 29, 2020 at 7:07 am #1218393DavidStaffCustomer SupportHi there,
in this code Leo provided:
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) { if ( 'date' === $item ) { return ' | '; } return $output; }, 50, 2 );
Change
if ( 'date' === $item ) {
toif ( is_single() && 'date' === $item ) {
March 29, 2020 at 7:38 am #1218417fellows2020Hi David, I changed the code, but it didn’t do anything. (I cleared my cache, but still nothing.)
March 29, 2020 at 8:46 am #1218603DavidStaffCustomer Supporttry changing it to:
if ( is_single() && 'date' === $item ) {
March 31, 2020 at 5:03 am #1220606fellows2020Hi David,
That’s the same code you suggested the first time around. When I tried putting into my functions file in place of if ( ‘date’ === $item ) { , it did not make any difference. Is there something else I can try? Thank you.
March 31, 2020 at 6:28 am #1220693DavidStaffCustomer SupportIts not the same – i changed it in both places above. Give it a try and let me know.
April 1, 2020 at 1:19 pm #1222673fellows2020It worked. thank you!
April 2, 2020 at 1:58 am #1223081DavidStaffCustomer SupportAwesome ๐
-
AuthorPosts
- You must be logged in to reply to this topic.