【问题标题】:Wordpress enqueue multiple stylesheets before </head> tagWordpress 在 </head> 标记之前将多个样式表排入队列
【发布时间】:2020-03-12 17:21:03
【问题描述】:

我想在结束 head 标记之前将多个 css 文件加载到 wordpress 中。以下代码有效,但它被关闭 head 标签之前的另一个样式表否决:

    function alt_styles()     
{    
    wp_enqueue_style( 'bb-style', '/wp-content/uploads/bb-style.css' );
    wp_enqueue_style( 'bb-landing', '/wp-content/uploads/bb-second-style.css' ); 
}

add_filter( 'wp_enqueue_scripts', 'alt_styles', 10000000000 ); 

有谁知道如何在 dom 中降低这两种样式(就在结束的 head 标签之前)?

【问题讨论】:

  • 这能回答你的问题吗? Ordering Wordpress Stylesheets?
  • 这里已经回答了这个问题:stackoverflow.com/a/7897325/2355051 看看是否可行。
  • 应该是add_action 并使用wp_print_styles
  • 不幸的是,它不起作用:(我们希望在结束 head 标记之前加载两个 css 文件。在您的示例中它只有一个文件。我们已经让它与其他代码一起加载在结束标记之前。但是我们不能在结束标记之前加载 2 个 css 文件。如果有人知道代码应该是什么就完美了

标签: php wordpress function stylesheet enqueue


【解决方案1】:

您可以使用 wp_head 手动添加脚本。

// Add scripts to wp_head()
function child_theme_head_script() { ?>
    <!-- This is injected last -->
<?php }
add_action( 'wp_head', 'child_theme_head_script', 999 );

您需要自己包含脚本的路径

【讨论】:

  • 这里需要添加什么代码?你能完成代码吗?现在不行了。我们在哪里包含路径?您能否完成它,然后我们只更改正确位置的路径。
  • 你能提供一个屏幕截图吗?该代码100%有效。我一直将它与许多不同的主题一起使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-16
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
相关资源
最近更新 更多