如何添加样式表来插入插件

时间:2014-03-23 02:03:50

标签: php wordpress-plugin

我查看了Action HooksFilter Hooks,但我找不到一个将脚本和样式表添加到<head>的函数。也许我不应该这样做这样做?

function juicyreviews_show_reviews(){
    # Link certain scripts and stylesheets in the head.
    # Like... masonry, jQuery, modernizr.js

    return "<div>I need scripts and styles.</div>";
}

add_shortcode('juicy_reviews', 'juicyreviews_show_reviews');

1 个答案:

答案 0 :(得分:1)

您需要在函数中对这些样式进行排队,然后您需要将该操作应用于该函数。

function juicyreviews_show_reviews(){
    wp_enqueue_script('masonry', '/path/to/masonry.js');
    wp_enqueue_style('my_css', '/path/to/my_css.css');
}

然后,您可以使用wp_head绑定scripts操作。 note 只有脚本/样式可以驻留在此函数中。

add_action('wp_head', 'juicyreviews_show_reviews');