首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >覆盖子主题中的后置格式

覆盖子主题中的后置格式
EN

WordPress Development用户
提问于 2016-06-23 18:29:25
回答 2查看 866关注 0票数 0

我使用的是一个只有视频帖子格式的子主题,但是父主题定义了所有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' ) );

但不起作用。在不修改父主题的情况下,我如何做到这一点?

EN

回答 2

WordPress Development用户

发布于 2016-06-23 18:48:28

为您的after_setup_theme设置高于父主题的优先级是非常重要的。默认优先级是10。以twentysixteen为例,在子主题的'after_setup_theme'操作上使用优先级11。举例如下:

代码语言:javascript
复制
function twentysixteen_child_setup() {
    add_theme_support( 'post-formats', array(
        'video',
    ) );
}
add_action( 'after_setup_theme', 'twentysixteen_child_setup', 11 );
票数 1
EN

WordPress Development用户

发布于 2016-06-23 18:49:30

确保您不仅在functions.php中调用这些函数,而且在正确的时间使用add_action()调用它们。尝试以下几点:

代码语言:javascript
复制
// 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' ) );
}

可能发生的情况是,在添加主题支持之前,您正在尝试删除它。

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/230574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档