Archived topic
Different entry title
5 replies · Started by webintas on October 28, 2022
Hi there,
I want to have the entry title to be something else than the post title. The post title is often short and used for menu item labels and <title> tag.
However I would like to have the h1 entry title on the page/post be longer and more specific. How can the post title and entry title be different?
Best Regards,
Peter
Hi there,
you would need somewhere to store the shortened Post Title.
Do you use any plugins for adding custom fields, such as ACF or Meta box ?
Hi David,
I prefer ACF.
Ok, so you need to create an ACF Field to add your title text.
It will be easier if this stores the Long title, otherwise there are some many other places where to update the other title.
Then try this PHP Snippet:
function db_swap_content_title( $title ) {
$long_title = get_field( 'your_acf_title_field' );
if (is_admin() || !in_the_loop() || !$long_title ) {
return $title;
}
return $long_title;
}
add_filter( 'the_title', 'db_swap_content_title' );
You need to update your your_acf_title_field
This in theory should replace only the content title within the loop so it will affect single and archives.
Awesome, thank you! :-)
You're welcome