0

我对 Wordpress 还很陌生,但我确实了解儿童主题。
这是我第一次遇到带有插件的主题,该插件有自己的样式表排队。以下代码是否已经将预订插件的样式表添加到主父样式表中(所以我不需要在子主题中包含它),或者这是一个额外的排队样式表,我还必须单独包含它在我孩子的主题中。

任何关于此代码究竟是什么以及如何与父样式一起使用的解释都将不胜感激。Wordpress codex 在这方面几乎毫无用处。

{
wp_enqueue_style( 'villagio-style', get_stylesheet_uri(), array(), 
villagio_get_theme_version() );
    if ( is_plugin_active( 'motopress-hotel-booking/motopress-hotel-
booking.php' ) ) {
    wp_enqueue_style( 'villagio-motopress-hotel-booking', 
get_template_directory_uri() . '/css/motopress-hotel-booking.css', 
array('villagio-style'), villagio_get_theme_version(), 'all' );
}
4

2 回答 2

0

如果我理解正确,您只想在父主题中加入 CSS,请尝试以下操作:

if (is_plugin_activate( 'plugin-name' ) && ! is_child_theme() ) { 
  //the code will show only in parent theme 
}

参考这里

于 2018-01-16T16:16:16.713 回答
0

是的,您可以将该代码放入您的子主题functions.php文件中。motopress-hotel-booking.css当插件处于活动状态时,它将调用文件motopress-hotel-booking.php。这是完整的代码:

function custom_add_css_for_theme()
{
    wp_enqueue_style('villagio-style', get_stylesheet_uri(), array(), villagio_get_theme_version());

    if (is_plugin_active('motopress-hotel-booking/motopress-hotel-booking.php')) {
        wp_enqueue_style('villagio-motopress-hotel-booking', get_template_directory_uri() . '/css/motopress-hotel-booking.css', array('villagio-style'), villagio_get_theme_version(), 'all');
    }
}
add_action( 'wp_enqueue_scripts', 'custom_add_css_for_theme' );

没关系,从哪里调用函数(从子主题或父主题)。函数get_template_directory_uri()返回父主题的目录,即使您从子主题调用它。

于 2018-01-16T17:37:30.543 回答