Archived topic
How to move entry-meta before entry-title
5 replies · Started by Milo Lam on June 14, 2021
Hi, in my <header class="entry-header"></header> I want to move <div class="entry-meta"></div> before <h2 class="entry-title"></h2>. This is what I have now. How would I go about doing this? Thank you!
Hi there,
try adding this PHP Snippet:
function tu_move_posted_on() {
remove_action( 'generate_after_entry_title', 'generate_post_meta',10 );
add_action( 'generate_before_entry_title', 'generate_post_meta' );
}
add_action( 'wp','tu_move_posted_on' );
Hi David,
Thank you for the prompt response. I phrased my issue incorrectly. This is what I'm trying to instead.
Specifically, In <header class="entry-header"></header> I need to move <span class="cat-links"></span> before <h2 class="entry-title"></h2>
The <div class="entry-meta"></div> should remain at the same position which is after <h2 class="entry-title"></h2>
Thank you!
Hi Milo,
Hi David,
Thank you for the prompt response. I phrased my issue incorrectly. This is what I’m trying to instead.Specifically, In <header class="entry-header"></header> I need to move <span class="cat-links"></span> before <h2 class="entry-title"></h2>
The
should remain at the same position which is after <h2 class="entry-title"></h2>
Thank you!
Ah, you mean you basically want to move the category links only and put it above the entry header?
If that's the cause, you can disable the post category links on the customizer setting found in Appearance > customize > Layout > Blog and then manually re-add it by hooking it on generate_before_content hook.
Try this out:
add_action('generate_before_content', function(){
$term_separator = apply_filters( 'generate_term_separator', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ), 'categories' );
$categories_list = get_the_category_list( $term_separator );
if ( $categories_list ) {
echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'generate_category_list_output',
sprintf(
'<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
$categories_list,
apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
)
);
}
},20);
Got it! Thanks
No problem. :D