[Support request] Add Post Category beside Post Date and Poster Name

Home Forums Support [Support request] Add Post Category beside Post Date and Poster Name

Home Forums Support Add Post Category beside Post Date and Poster Name

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #1260478
    ben2619

    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.

    #1261437
    Leo
    Staff
    Customer Support

    Hi there,

    You can try these two filters to tweak the meta that shows up on top and bottom:
    https://docs.generatepress.com/article/generate_header_entry_meta_items/
    https://docs.generatepress.com/article/generate_footer_entry_meta_items/

    Let me know if this helps 🙂

    #1261601
    ben2619

    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.

    #1261724
    Leo
    Staff
    Customer Support
    #1261832
    ben2619

    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.

    #1261850
    Leo
    Staff
    Customer Support

    Try this instead:

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

    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.

    #1261911
    Leo
    Staff
    Customer Support

    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 );
    #1261945
    ben2619

    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 🙂

    #1262005
    Leo
    Staff
    Customer Support

    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 🙂

    #1262201
    ben2619

    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.

    #1262258
    Leo
    Staff
    Customer Support

    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?

    #1262338
    ben2619

    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.

    #1262882
    David
    Staff
    Customer Support
    #1263075
    ben2619

    Works great! Thank you.

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