0

I have found this filter which allows me to change the default name but this changes it for pages and posts. I just want to change it for posts. Is this possible?

add_filter('default_page_template_title', function() {
    return __('new default name for posts only', 'your_text_domain');
});
1

Yes, and one way is by accessing the global $post variable and then check if it's for a post of the post type (or any custom post types). E.g.

add_filter( 'default_page_template_title', function ( $label ) {
    global $post;
    if ( 'post' === get_post_type( $post ) ) {
        return __( 'new default name for posts only', 'your_text_domain' );
    }

    return $label;
} );

Or the other way is by checking if the current screen's ID is edit-post (or edit-<post type>), and you'd just need to change the above if condition to:

if ( 'edit-post' === get_current_screen()->id )
2
  • 1
    Brilliant, thanks!! – user8463989 Feb 5 at 10:13
  • 1
    Glad it worked for you :), and sorry I was focused on wp-admin/edit.php - on the post-new.php and post.php pages, the screen ID is post (or a_post_type, i.e. the post type slug). – Sally CJ Feb 6 at 5:55

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.