这是您可以做的:
1-将CSS放在一个单独的文件中,并将其保存在主题目录中
2-在中添加以下代码functions php
:
function wpse_89494_enqueue_scripts() {
if ( has_nav_menu( \'secondary\' ) ) {
wp_enqueue_style(
\'wpse_89494_style_1\',
get_template_directory_uri() . \'/your-style_1.css\'
);
}
if ( has_nav_menu( \'primary\' ) ) {
wp_enqueue_style(
\'wpse_89494_style_2\',
get_template_directory_uri() . \'/your-style_2.css\'
);
}
if ( ! has_nav_menu( \'primary\' ) && ! has_nav_menu( \'secondary\' ) ) {
wp_enqueue_style(
\'wpse_89494_style_3\',
get_template_directory_uri() . \'/your-style_3.css\'
);
}
}
add_action( \'wp_enqueue_scripts\', \'wpse_89494_enqueue_scripts\' );