One of my customer has many pages that have the same titles, although their content is different.
They would like to be able to give them “admin titles” in order to differentiate them in the
admin list.
I was thinking of adding an ACF extra field “Admin Title”. If this field is filled, then on the page listing in the admin, I would like to use it.
Is there an admin filter that is called when generating the page list ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can use the_title hook to change the title of the post in the admin, something like this
add_filter( 'the_title', 'custom_post_title', 10, 2 );
function custom_post_title( $title, $post_id ) {
// Return early if not in the admin
if ( !is_admin() )
return $title;
$post_type = get_post_type( $post_id );
// You only need to change the title for pages
if ( 'page' !== $post_type )
return $title;
$custom_title = get_field( 'your_custom_title_acf_key', $post_id );
// If custom title is present, display it instead of original
if ( $custom_title ) {
$title = $custom_title;
}
return $title;
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0