• I use Post Formats to style posts. In my case I use ‘Chat’ and ‘Quote’. Where I use the ‘Chat’ format to indicate posts that are featured and the ‘Quote’ format to indicate posts that have a large title size.

    In the Classic Editor I had renamed them ‘Featured’ and ‘Typography’. This makes it easier for the editors/writers to know which one to choose for their posts. But I can’t get a script to rename them to work in the Block Editor.

    // Enable support for Post Formats.
    add_theme_support( 'post-formats', [ 'chat', 'quote' ] );
    add_post_type_support( 'post', 'post-formats' );
    
    function custom_rename_block_editor_post_formats( $editor_settings ) {
    
    // Define custom labels for post formats
    
    $custom_formats = [
    
    'Chat' => __( 'Featured', 'textdomain' ), 
    
    'Quote' => __( 'Typografic', 'textdomain' ) 
    
    ];
    
    // Modify post format labels in the block editor settings
    
    if ( isset( $editor_settings['settings']['formats'] ) ) {
    
    foreach ( $custom_formats as $format => $label ) {
    
    if ( isset( $editor_settings['settings']['formats'][ $format ] ) ) {
    
    $editor_settings['settings']['formats'][ $format ]['title'] = $label;
    
    } } }
    
    return $editor_settings;
    
    }
    
    add_filter( 'block_editor_settings_all', 'custom_rename_block_editor_post_formats' );

    This code does nothing. At the suggestions of others I also tried with gettext instead of textdomain. Which also did not work. I’m testing the code on a fresh WordPress 6.5.2 install with Twenty Twenty-Four (twentytwentyfour) theme.

    It seems I may be using the wrong filter? How do I get this code to work?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please make sure to replace 'textdomain' with your actual theme or plugin text domain in your code.

    Thread Starter daricedotorg

    (@daricedotorg)

    That did not fix the problem. I’m testing it on a clean WordPress install with the TwentyTwentyFour theme. I still get ‘Chat’ and ‘Quote’ in the Block Editor instead of the rename.

    // Enable support for Post Formats.
    
    add_theme_support( 'post-formats', [ 'chat', 'quote' ] );
    
    add_post_type_support( 'post', 'post-formats' );
    
    function custom_rename_block_editor_post_formats( $editor_settings ) {
    
    // Define custom labels for post formats
    
    $custom_formats = [
    
    'Chat' => __( 'Featured', 'twentytwentyfour' ),
    
    'Quote' => __( 'Typografic', 'twentytwentyfour' )
    
    ];
    
    // Modify post format labels in the block editor settings
    
    if ( isset( $editor_settings['settings']['formats'] ) ) {
    
    foreach ( $custom_formats as $format => $label ) {
    
    if ( isset( $editor_settings['settings']['formats'][ $format ] ) ) {
    
    $editor_settings['settings']['formats'][ $format ]['title'] = $label;
    
    } } }
    
    return $editor_settings;
    
    }
    
    add_filter( 'block_editor_settings_all', 'custom_rename_block_editor_post_formats' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rename Post Formats options’ is closed to new replies.