[Resolved] Help with custom meta after title post

Home Forums Support [Resolved] Help with custom meta after title post

Home Forums Support Help with custom meta after title post

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1213183
    fellows2020

    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.

    #1213458
    Leo
    Staff
    Customer Support

    Hi 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 ๐Ÿ™‚

    #1213505
    fellows2020

    This 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!

    #1213545
    Leo
    Staff
    Customer Support

    Add this CSS:

    .entry-meta, .affiliate {
        display: inline-block;
    }
    .affiliate {
        font-size: 85%;
    }
    .affiliate:before {
        content: " | ";
    }
    #1213567
    fellows2020

    Hi, 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.

    #1218393
    David
    Staff
    Customer Support

    Hi 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 ) { to if ( is_single() && 'date' === $item ) {

    #1218417
    fellows2020

    Hi David, I changed the code, but it didn’t do anything. (I cleared my cache, but still nothing.)

    #1218603
    David
    Staff
    Customer Support

    try changing it to:

    if ( is_single() && 'date' === $item ) {

    #1220606
    fellows2020

    Hi 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.

    #1220693
    David
    Staff
    Customer Support

    Its not the same – i changed it in both places above. Give it a try and let me know.

    #1222673
    fellows2020

    It worked. thank you!

    #1223081
    David
    Staff
    Customer Support

    Awesome ๐Ÿ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.