2

I want to modify dynamically the Heading1 that appears on top of the Admin List of posts. E.g. the Page heading of the Pages list. pages admin list

I have exhausted all possible searches I could think of and nothing relevant came out.

Is there any function, filter, etc that allows us to modify what the content of the H1 heading of a custom post type list page would be?

I actually want to be able to add the title of a taxonomy when the list is filtered by that taxonomy.

  • 1
    There is no dedicated filter for this. See wp-admin\edit.php. WP uses $post_type_object->labels->name to output the text, so modifying that is likely going to require some kind of hacky approach since the the label text is used in other places as well. – Dave Romsey Sep 26 '18 at 20:41
  • 1
    I see:( -but thanks anyway @DaveRomsey - My fallback thought is to do some js... – FFrewin Sep 26 '18 at 20:57
3

When you take a look at wp-admin/edit.php, you'll see that this string is printed with this line:

echo esc_html( $post_type_object->labels->name );

So there is no filter to modify it in edit.php.

There are no filters in get_post_type_object also, so we can't change it in there too, but...

The object for given post type is stored in global variable called $wp_post_types, so you can modify it:

function change_page_post_type_object() {
    global $wp_post_types;

    $wp_post_types['page']->labels->name = 'Not-Pages ;)';
}
add_action( 'init', 'change_page_post_type_object' );

And that's the result:

enter image description here

|improve this answer|||||
  • 1
    The issue I had with this is that it stomps on the name label indiscriminately. At a glance, I only see it modifying the <title> element of edit.php, which may actually be desirable in this case. Conditional statements should be added to this solution to minimize any possible fallout (ensure we're on edit.php, page is the post type, taxonomy is being filtered, etc) because it's reasonable to expect that plugins will make use of post type labels. – Dave Romsey Sep 26 '18 at 21:57
  • 2
    Yes, of course you’re right. The problem is that I don’t know what exactly should be changed and what is the reason for that change. If I’d change the title of posts list, then most of the times I’d like to also change that CPT name in other places... But that’s just guessing... – Krzysiek Dróżdż Sep 26 '18 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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