Site logo

Archived topic

Add Post Category beside Post Date and Poster Name

15 replies · Started by ben2619 on April 28, 2020

Viewing posts 1–15 of 16

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.

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

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

Try this instead:

add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
	if ( 'categories' === $item ) {
        return ' Published in ';
    }
    return $output;
}, 50, 2 );

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

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

Thanks. 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 :-)

Can 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 :)

Thanks 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 category

Here's the link to the image: Sample page.

If 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?

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

Works great! Thank you.

This archived topic is closed to new replies.