我试过了if ( ! did_action( \'get_header\' ) ) 但似乎不起作用。
请重试,但请按此方式:
add_filter( \'theme_mod_understrap_container_type\', \'override_container_type\' );
function override_container_type( $value ) {
if ( did_action( \'get_header\' ) && ! did_action( \'get_footer\' ) ) {
if ( get_field(\'container_type\') !== \'inherit\' ){
return get_field(\'container_type\');
}
}
// For header.php and footer.php
return $value;
}
基本上,这里是您需要的条件:
did_action( \'get_header\' ) && ! did_action( \'get_footer\' )
更新如果您使用的是子主题,这些主题如何:
将此添加到functions.php:function my_theme_container_type( $location = null ) {
if ( \'main\' === $location ) {
if ( $value = get_field(\'container_type\') ){
return $value;
}
}
return get_theme_mod( \'understrap_container_type\' );
}
编辑single.php 和page.php 文件,并更改此项:$container = get_theme_mod( \'understrap_container_type\' );
至$container = my_theme_container_type( \'main\' );
并将其从functions.php):add_filter( \'theme_mod_understrap_container_type\', \'override_container_type\' );
function override_container_type() {
...
}
这可能回答不了问题,但如果我是你,我会这么做的