0

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 ?

1 Answer 1

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;
}
4
  • oh right... silly me, I was searching for something complicated when it was plain simple. Thanks !
    – Pierre
    Oct 6, 2020 at 8:19
  • hmm somehow it does not work well. It does change the title, but instead of getting the value of $title, it just display (no title)
    – Pierre
    Oct 6, 2020 at 8:24
  • Do you return a $title at the end of the callback function?
    – geouser
    Oct 6, 2020 at 8:46
  • yes. In fact, just returning the $title without any other code isn't working. I am going to try on a clean WP install, and if it works I will search for another filter somewhere that might break it...
    – Pierre
    Oct 7, 2020 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.