Site logo

Archived topic

Reorder header entry Meta items

7 replies · Started by Melissa on December 12, 2021

Viewing posts 1–8 of 8

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!

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);

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?

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.

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?

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

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.

This archived topic is closed to new replies.