- This topic has 5 replies, 3 voices, and was last updated 5 years, 6 months ago by Leo.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
August 10, 2018 at 5:13 pm #645381Luong
Hello,
How can I display the category meta on a single post above the title instead as it is below the content?
Thanks for your help!
August 10, 2018 at 6:30 pm #645410LeoStaffCustomer SupportHi there,
Try this snippet:
add_filter( 'generate_category_list_output','lh_remove_categories' ); function lh_remove_categories( $categories ) { if ( is_single() ) { return ''; } return $categories; } add_action( 'generate_before_entry_title','lh_single_cats_above_title' ); function lh_single_cats_above_title() { if ( is_single() ) { $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) ); if ( $categories_list ) { printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } } }
Adding PHP: https://docs.generatepress.com/article/adding-php/
Let me know ๐
August 11, 2018 at 12:54 am #645531LuongThank you a lot, it works!
August 11, 2018 at 8:17 am #645752LeoStaffCustomer SupportNo problem ๐
October 15, 2018 at 1:54 am #701113andrewHi,
I used this code:add_filter( 'generate_category_list_output','lh_remove_categories' ); function tu_remove_categories( $categories ) { if ( is_single() ) { return ''; } if ( is_home() ) { return ''; } return $categories; } add_action( 'generate_before_entry_title','lh_single_cats_above_title' ); function lh_single_cats_above_title() { if ( is_single() ) { $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) ); if ( $categories_list ) { printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } } if ( is_home() ) { $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) ); if ( $categories_list ) { printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } } }
But my error_log_php into cpanel display shows me a lot of error:
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'lh_remove_categories' not found or invalid function name in /home/****/public_html/wp-includes/class-wp-hook.php on line 286
What’s wrong and how do I fix it?
Thank you very much
October 15, 2018 at 9:42 am #701493LeoStaffCustomer SupportCan you open a new topic for your question?
Thanks!
-
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
- The topic ‘Display post categories above title’ is closed to new replies.