我使用的是一个只有视频帖子格式的子主题,但是父主题定义了所有post格式:
add_theme_support( 'post-formats', array( 'gallery', 'link', 'image', 'quote', 'video', 'audio', 'chat' ) );
我试过:
remove_theme_support( 'post-formats' ); add_theme_support( 'post-formats', array( 'video' ) );
但不起作用。在不修改父主题的情况下,我如何做到这一点?
发布于 2016-06-23 18:48:28
为您的after_setup_theme设置高于父主题的优先级是非常重要的。默认优先级是10。以twentysixteen为例,在子主题的'after_setup_theme'操作上使用优先级11。举例如下:
function twentysixteen_child_setup() {
add_theme_support( 'post-formats', array(
'video',
) );
}
add_action( 'after_setup_theme', 'twentysixteen_child_setup', 11 );发布于 2016-06-23 18:49:30
确保您不仅在functions.php中调用这些函数,而且在正确的时间使用add_action()调用它们。尝试以下几点:
// in your Child Theme's functions.php
// Use the after_setup_theme hook with a priority of 11 to load after the
// parent theme, which will fire on the default priority of 10
add_action( 'after_setup_theme', 'remove_post_formats', 11 );
function remove_post_formats() {
remove_theme_support( 'post-formats' );
add_theme_support( 'post-formats', array( 'video' ) );
}可能发生的情况是,在添加主题支持之前,您正在尝试删除它。
https://wordpress.stackexchange.com/questions/230574
复制相似问题