- This topic has 34 replies, 2 voices, and was last updated 3 years, 11 months ago by David.
-
AuthorPosts
-
December 6, 2017 at 5:03 am #442913Florian
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,
FlorianDecember 6, 2017 at 8:55 am #443117LeoStaffCustomer SupportHi 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/
December 6, 2017 at 10:30 am #443210FlorianHi 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,
FlorianDecember 6, 2017 at 11:02 am #443237LeoStaffCustomer SupportHmm 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?
December 6, 2017 at 11:09 am #443245FlorianOkay, 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
December 6, 2017 at 11:46 am #443288TomLead DeveloperLead DeveloperDo you want the author to display? Or only the categories and tags?
December 6, 2017 at 11:50 am #443295Florianno author, only category and maybe also the tags
December 6, 2017 at 2:07 pm #443405TomLead DeveloperLead DeveloperTry 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 }
December 7, 2017 at 12:14 am #443634Florianthanks but it still shows the date. I have removed the date now with CSS display none
December 7, 2017 at 12:38 am #443667TomLead DeveloperLead DeveloperYou can remove the date in Customize > Layout > Blog.
December 7, 2017 at 12:41 am #443674FlorianI 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
December 7, 2017 at 10:47 am #444147TomLead DeveloperLead DeveloperAh right. You can disable it in the Customizer, then add this CSS:
.entry-header .entry-meta { display: block; }
December 7, 2017 at 11:06 am #444170FlorianFot 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.
December 7, 2017 at 12:05 pm #444232TomLead DeveloperLead DeveloperThat works too 🙂
March 26, 2018 at 1:08 pm #531566JeffreyHi 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 ?
-
AuthorPosts
- You must be logged in to reply to this topic.