[Resolved] Display post categories and tags below title

Home Forums Support [Resolved] Display post categories and tags below title

Home Forums Support Display post categories and tags below title

Viewing 15 posts - 1 through 15 (of 35 total)
  • Author
    Posts
  • #442913
    Florian

    Hello,

    How can I display the category and tags meta on a single post below the title instead as it is below the text?

    Should I use the hooks for that and what code do I need to place there? Sorry, could not figure it out.

    Thanks for your help!

    Beste regards,
    Florian

    #443117
    Leo
    Staff
    Customer Support

    Hi there,

    First move it to below title:

    add_action( 'after_setup_theme','tu_move_posted_on' );
    function tu_move_posted_on() {
        remove_action( 'generate_after_entry_title', 'generate_post_meta' );
        add_action( 'generate_after_entry_title', 'generate_post_meta' );
        add_filter( 'generate_category_list_output', '__return_false' );
    }

    Then add this:

    add_filter( 'generate_post_date_output', 'tu_categories_to_date' );
    function tu_categories_to_date( $output ) {
        $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
        $categories_list = sprintf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
            _x( 'Categories', 'Used before category names.', 'generatepress' ),
            $categories_list
        );
    
        return $categories_list . $output;
    }

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #443210
    Florian

    Hi Leo,

    Thanks, I have added this code but it only has moved the category below the title on the front page (post list) and not on the post itself. What can I do to move the category/tags on the post below the title?

    Best regards,
    Florian

    #443237
    Leo
    Staff
    Customer Support

    Hmm I tested the code and it moved them on single posts too: https://s33.postimg.org/ezlkrk5lr/2017-12-06_1102.png

    Can you link me to a single post?

    #443245
    Florian

    Okay, I found the problem: I have to display the post date to see the category below the title. But the thing is I don’t want to show the post date. Is there a solutions for that? Thanks

    #443288
    Tom
    Lead Developer
    Lead Developer

    Do you want the author to display? Or only the categories and tags?

    #443295
    Florian

    no author, only category and maybe also the tags

    #443405
    Tom
    Lead Developer
    Lead Developer

    Try this:

    add_action( 'generate_after_entry_title', 'tu_add_meta_below_title' );
    function tu_add_meta_below_title() {
        $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
        $categories_list = sprintf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
            _x( 'Categories', 'Used before category names.', 'generatepress' ),
            $categories_list
        );
    
        $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
        $tags_list = sprintf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
    		esc_html_x( 'Tags', 'Used before tag names.', 'generatepress' ),
    			$tags_list
    	);
    
    	?>
    	<div class="entry-meta">
    		<?php echo $categories_list; ?>
    		<?php echo $tags_list; ?>
    	</div>
    	<?php
    }
    #443634
    Florian

    thanks but it still shows the date. I have removed the date now with CSS display none

    #443667
    Tom
    Lead Developer
    Lead Developer

    You can remove the date in Customize > Layout > Blog.

    #443674
    Florian

    I know. But then it will also not show the category. I think the code you have provided me connects the date with the category in some way

    #444147
    Tom
    Lead Developer
    Lead Developer

    Ah right. You can disable it in the Customizer, then add this CSS:

    .entry-header .entry-meta {
        display: block;
    }
    #444170
    Florian

    Fot me the only thing that works is to disable the Date by CSS:

    .entry-date {
    	display: none;
    	 }

    This way I only see the Category below the title and that’s fine.

    #444232
    Tom
    Lead Developer
    Lead Developer

    That works too 🙂

    #531566
    Jeffrey

    Hi there,

    I saw the coding that you have provided for the tags and category to show after the post title…

    But where should I paste the code at ?

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