add_action('wp_head', 'add_favicon');
add_action('wp_head', 'facebook_open_graph' );
add_action('wp_head', 'add_theme_css_style');
add_action('wp_head', 'add_theme_google_fonts');
add_action( 'wp_enqueue_scripts', 'add_script_footer', 25 );
function add_theme_css_style() {
wp_enqueue_style ('bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '1.0.0');
wp_enqueue_style ('slick-main', get_template_directory_uri() . '/assets/js/slick/slick.css', array(), '1.0.0');
wp_enqueue_style ('slick-theme-main', get_template_directory_uri() . '/assets/js/slick/slick-theme.css', array(), '1.0.0');
wp_enqueue_style ('aos-main', get_template_directory_uri() . '/assets/aos/aos.css', array(), '1.0.0');
wp_enqueue_style ('woocommerce', get_template_directory_uri() . '/assets/css/woocommerce.css', array(), '1.0.0');
wp_enqueue_style ('congrats-js-form', get_template_directory_uri() . '/congrats/congrats.css', array(), '1.0.0');
wp_enqueue_style ('main-theme-style', get_template_directory_uri() . '/assets/css/styles.css', array(), '1.0.0');
}
add_action('wp_head', 'add_theme_css_style');此行负责将样式连接到 wp_head 钩子
add_action( 'wp_enqueue_scripts', 'add_script_footer', 25 );此行负责将脚本连接到页脚(footer)
无需删除文档链接!!!请解释为什么add_action('wp_head', "func_style")它仍然在页脚中输出样式
谢谢你。
样式转到页脚是因为您使用了错误的钩子。
要运行脚本和样式,您需要使用
wp_enqueue_scripts. 这个钩子是 WordPress 对脚本和样式进行排队的地方。钩子wp_head在后面执行,看内核中钩子的执行顺序。对于优先级为 8的事件
wp_head(即在执行您的事件之前add_theme_css_style- 默认情况下它的优先级为 10),内核调用函数wp_print_styles,该函数将页面上的样式出列。之后添加的任何样式都将保留在队列中,并将由页脚中的核心呈现。