[Support request] Reorder header entry Meta items

Home Forums Support [Support request] Reorder header entry Meta items

Home Forums Support Reorder header entry Meta items

  • This topic has 7 replies, 4 voices, and was last updated 1 month ago by Elvin.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2046611
    Melissa

    I’m using the following code to reorder meta items, but I still have a couple of items that are backwards.

    // rearrange meta order
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'comments-link',
    	    'date',
        );
    } );
    add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
        if ( '' === $item ) {
            return '';
        }
        if ( 'comments-link' === $item ) {
            return ' ';
        }
        if ( is_single() && 'date' === $item ) {
            return ' This post may contain affiliate links, see Full Disclosure link in footer</a>. | ';
        }
        return $output;
    }, 50, 2 );

    What I’m trying to achieve is this format directly under the Title of the article:

    by [Author Name} |[comment-count] | Updated: [Last Updated Date]
    This post may contain affiliate links, see full disclosure.

    what I’m currently seeing is:
    by [Author Name} |[comment-count] | This post may contain affiliate links, see full disclosure.
    Updated: [Last Updated Date]

    Could someone please assist? Thank you kindly!

    #2046725
    David
    Staff
    Customer Support

    Hi there,

    i would leave the disclosure out the meta, and instead hook it in after the post meta like so:

    add_action('generate_after_entry_title', function(){
        if ( is_single() ) {
            ?>
                // output your HTML here
            <?php
        }
    },15);
    #2046731
    Melissa

    Okay, Thank you for that. I did give it a try, but then it breaks it into giant words and loses the formatting.

    see

    I tried using this css to remove the gap & maintain the font formatting:

    .entry-meta, .aff {
        display: inline-block !important;
    }
    .aff {
        font-size: 15px!important;
    }

    but that still leaves a giant gap between the lines

    snip

    Here’s how it looks now, with the big gap between the lines:
    meta gap

    How do I get it to stay inline so it’s nice and neat without a big gap?

    #2046835
    Leo
    Staff
    Customer Support

    Hi there,

    Have you considered building a custom post meta using a block element and GenerateBlocks?
    https://docs.generatepress.com/article/block-element-post-meta-template/

    It would be the best and easiest method.

    #2046859
    Melissa

    Not really, since I have no idea how to code that and then I have to figure out how to remove the other meta so I don’t have double meta. That kinda sounds like a helluva lot harder.

    #2046863
    Leo
    Staff
    Customer Support

    There would be absolutely no code required if you use a block element – the current way using PHP is much more complicated.

    Then you simply have to remove the PHP you’ve added and that should be it.

    Can you take a look at the video first?

    #2046937
    Melissa

    Leo, I don’t know anything about blocks, my entire site is using classic editor only. I’m currently using a hook to insert the affiliate disclosure and I was told to get that out of there because it screws up the SEO, that it must be immediately at the end of the meta.

    I don’t get the same screen that your video is showing, not even remotely close.There is no drop down box of element types. Unfortunately, using blocks is completely greek to me, it’s super confusing, I’m used to html & css.

    I’ve got it to work (mostly) adding a filter using an if/else condition so it only shows on posts and not in categories.

    Using a Hook it was:
    using a hook

    Now, using else/if:
    using else if condition

    #2046976
    Elvin
    Staff
    Customer Support

    Hi Melissa,

    If I may suggest an alternative, you can actually make a ‘disclosure’ post meta item so you don’t have to filter the other items.

    Here’s an example:

    Creating a ‘disclosure’ post meta item.

    add_action( 'generate_post_meta_items', function( $item ) {
        if ( 'disclosure' === $item ) {
            echo '<span class="disclosure"> This post may contain affiliate links, see <a href="your link here">Full Disclosure link in footer</a> </span>';
        }
    } );

    Change the href value from your link here to the link of the full disclosure page.

    And then add it in to the header entry meta.

    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'comments-link',
    	'date',
            'disclosure'
        );
    } );

    This way, we don’t mess up the other entry items. 🙂

    Now as for the aligning to inline:

    It should already be inlined by default but since the disclosure message is long, it will wrap to the next line.

    A wise man once said:
    "Have you cleared your cache?"

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