Changing “Add New Post” to a string with unescaped HTML tags cannot be accomplished using only PHP: WordPress core escapes any HTML in the CPT’s label for that text.
Additionally (again, only using PHP), there is no way to remove that block of text: setting the add_new_item
label to blank when registering the CPT results in “Add New” being displayed.
Your best option is to use CSS to hide the core text, and then add your own <h1>
:
add_action( 'edit_form_top', static function () {
if ( empty( $_GET['post'] ) ) {
return;
}
$post_id = absint( $_GET['post'] );
if ( 'wpse416980' !== get_post_type( $post_id ) ) {
return;
}
echo '<style>.wrap h1.wp-heading-inline { display: none; }</style>';
printf(
'<h1>%s<span class="custom-class">%s</span></h1>',
__( 'Custom post title: ', 'custom-plugin' ),
get_the_title( $post_id )
);
} );