Addressed a bug in WordPress 5.4 and a custom post on HPB that prevented the block editor from working

⌛Time it takes to read this article: 5 minutes

update Last updated: July 6, 2026 at 7:12 PM

/* 【WordPress5.4】マルチファイルアップローダバグ対応 */
function my_admin_media_views_style() {
	if ( wp_style_is( 'media-views' ) ) {
		$style = <<<STYLE
div.moxie-shim.moxie-shim-html5,
div.moxie-shim.moxie-shim-html5 input[type="file"] {
	display: inline;
}
STYLE;
		wp_add_inline_style( 'media-views', $style );
	}
}
add_action( 'admin_enqueue_scripts', 'my_admin_media_views_style' );


Applying custom posts to block editor

Next question.

With WordPress 5.4, the functionality of the block editor (commonly known as Gutenberg) has been enhanced and it has become very easy to use, so all new posts are standardized to the block editor. (However, it is inconvenient that tags cannot be selected)

However, I couldn't use the convenient block editor for custom posts such as news and galleries.

Therefore, this time, it became possible to edit it in the block editor by modifying two functions regist_posttype_news described in the program "functions.regist_posttype_gallery" of the theme as follows.
Add two lines for each function. (set the value of the parameter 'show_in_rest' to true)

In the world of WordPress, it seems that there are not many users, but this site uses the homepage builder of JustSystems (transferred from developer IBM Japan in 2011) for the theme PHP program.

2022.07.28 update – Enable post excerpts as well

php
<?php
}
function regist_posttype_news(){
	register_post_type(
		'news',
		array(
		'label'         => 'ニュース',
		'hierarchical'  => false,
		'public'        => true,
		'has_archive'   => true,
		'supports'      => array(
		'title',
		'editor',
		'thumbnail',
		'comments',
		'excerpt'	// 抜粋を有効
		),
		'menu_position' => 5,
		'show_in_rest'  => true, // ブロックエディタ対応
		'menu_icon'     => get_template_directory_uri() . '/post-types/menu_news.png'
		)
	);

	register_taxonomy(
		'newscat',
		'news',
		array(
		'label'        => 'ニュースのカテゴリー',
		'show_in_rest' => true, // ブロックエディタ対応
		'hierarchical' => true,
		)
	);
}

php
function regist_posttype_gallery(){
	register_post_type(
		'gallery',
		array(
		'label'         => 'ギャラリー',
		'hierarchical'  => false,
		'public'        => true,
		'has_archive'   => true,
		'supports'      => array(
		'title',
		'editor',
		'thumbnail',
		'comments',
		'excerpt'	// 抜粋を有効
		),
		'menu_position' => 5,
		'show_in_rest'  => true, // ブロックエディタ対応
		'menu_icon'     => get_template_directory_uri() . '/post-types/menu_user.png'
		)
	);

	register_taxonomy(
		'gallerycat',
		'gallery',
		array(
		'label'        => 'ギャラリーのカテゴリー',
		'show_in_rest' => true, // ブロックエディタ対応
		'hierarchical' => true,
		)
	);
}

2026.07.05 Update
Below is the latest version of the snippet, aligned to the latest WordPress specifications. Apply custom gallery and news post types to the block editor.

php
// 投稿タイプ「ギャラリー」をブロックエディタに適用

function regist_posttype_gallery(){
    register_post_type(
        'gallery',
        array(
            'labels' => array(
                'menu_name'     => 'ギャラリー',     	// 左側の親メニュー名
                'name'          => 'ギャラリー', 	// パンくずリストや大タイトルに使用される名前
                'all_items'     => 'ギャラリー 一覧', 	// 子メニュー1行目
                'add_new_item'  => 'ギャラリーを追加', 	// 子メニュー2行目
                'singular_name' => 'ギャラリー',
            ),
            'hierarchical'  => false,
            'public'        => true,
            'has_archive'   => true,
            'supports'      => array(
                'title',
                'editor',
                'thumbnail',
                'comments',
                'excerpt' // 抜粋を有効
            ),
            'menu_position' => 5,
            'show_in_rest'  => true, // ブロックエディタ対応
            'menu_icon'     => 'dashicons-camera'
        )
    );

    register_taxonomy(
        'gallerycat',
        'gallery',
        array(
            'label'        => 'ギャラリーのカテゴリー',
            'show_in_rest' => true, // ブロックエディタ対応
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'regist_posttype_gallery' );


/* 管理画面一覧にギャラリーのカテゴリを表示 */
function manage_gallery_columns( $columns ) {
//	$columns['fcategory'] = 'ギャラリーのカテゴリー';
	$columns['gallery_category'] = 'ギャラリーのカテゴリー';
	return $columns;
}

function add_gallery_column( $column_name, $post_id ){
	if ( 'gallery_category' == $column_name ) {
		$fcategory = get_the_term_list( $post_id, 'gallerycat', '', '、' );
		if ( $fcategory ) {
			echo $fcategory;
		} else {
			echo __( 'None', '_hpb' );
		}
	}
}

add_filter( 'manage_edit-gallery_columns', 'manage_gallery_columns' );
add_action( 'manage_gallery_posts_custom_column', 'add_gallery_column', 10, 2 );

/* 管理画面のヘッダーにスマホ用のCSSのみを出力 */
add_action('admin_head', 'plugin_header_gallery');

function plugin_header_gallery() {
    $screen = get_current_screen();
    
    // ギャラリー 一覧画面のときだけ実行
    if ( isset($screen->post_type) && $screen->post_type === 'gallery' ) {
        ?>
        <style>
            /* スマホ表示(782px以下)で「ギャラリーのカテゴリー」列を非表示にする */
            @media (max-width: 782px) {
                .fixed .column-gallery_category {
                    display: none;
                }
            }
        </style>
        <?php
    }
}


// 投稿タイプ「ニュース」をブロックエディタに適用

function regist_posttype_news(){
    register_post_type(
        'news',
        array(
            'labels' => array(
                'menu_name'     => 'ニュース',     // 左側の黒い親メニュー名
                'name'          => 'ニュース',     // パンくずリストや大タイトルに使用される名前
                'all_items'     => 'ニュース一覧', // 子メニュー1行目だけを書き換え
                'add_new_item'  => 'ニュースを追加', // 子メニュー2行目
                'singular_name' => 'ニュース',
            ),
            'hierarchical'  => false,
            'public'        => true,
            'has_archive'   => true,
            'supports'      => array(
                'title',
                'editor',
                'thumbnail',
                'comments',
                'excerpt' // 抜粋を有効
            ),
            'menu_position' => 5,
            'show_in_rest'  => true, // ブロックエディタ対応
            'menu_icon'     => 'dashicons-megaphone'
        )
    );

    register_taxonomy(
        'newscat',
        'news',
        array(
            'label'        => 'ニュースのカテゴリー',
            'show_in_rest' => true, // ブロックエディタ対応
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'regist_posttype_news' );


/* 管理画面一覧にニュースのカテゴリを表示 */
function manage_news_columns( $columns ) {
//	$columns['fcategory'] = 'ニュースのカテゴリー';
	$columns['news_category'] = 'ニュースのカテゴリー';
	return $columns;
}

function add_news_column( $column_name, $post_id ){
	if ( 'news_category' == $column_name ) {
		$fcategory = get_the_term_list( $post_id, 'newscat', '', '、' );
		if ( $fcategory ) {
			echo $fcategory;
		} else {
			echo __( 'None', '_hpb' );
		}
	}
}

add_filter( 'manage_edit-news_columns', 'manage_news_columns' );
add_action( 'manage_news_posts_custom_column', 'add_news_column', 10, 2 );


/* 管理画面のヘッダーにスマホ用のCSSのみを出力 */
add_action('admin_head', 'plugin_header_news');

function plugin_header_news() {
    $screen = get_current_screen();
    
    // ニュース一覧画面のときだけ実行
    if ( isset($screen->post_type) && $screen->post_type === 'news' ) {
        ?>
        <style>
            /* スマホ表示(782px以下)で「ニュースのカテゴリー」列を非表示にする */
            @media (max-width: 782px) {
                .fixed .column-news_category {
                    display: none;
                }
            }
        </style>
        <?php
    }
}

This allows news articles to be edited in the block editor as shown below! 😀


Installing imagick

2020.05.03 Postscript
Installing imagick

Leave this problem as a memorandum.
In the core server, the module imagick that calls the image processing library ImageMagick from PHP is not installed in the standard PHP configuration.
Therefore, when you run Jetpack Site Health, you will see the warning screen "One or more recommended modules does not exist" shown below.

This issue is resolved by adding the extension module definition to the core server's php.ini file (php7.1) in the path below.

public_htmlfast-cgi-binphp71.ini

extension = imagick.so


After correcting php.ini, after a while, when executing site health, the warning "One or more recommended modules does not exist" disappears as shown below.

If you select "Information" ⇒ "Media Processing" on the site health screen, you can confirm that ImageMagick is installed as shown below.

Leave a Reply