我是WordPress的新手,正在为我的网站构建一个单一的页面模板。我想保留我的主要WordPress主题为大多数网站,但我有一个非常具体的应用程序,我想使用引导带只在几页。为了避免在主题更新时丢失我的自定义工作,我用页面模板创建了一个子主题,然后从WordPress中为适当的页面选择了该模板。
最后,我为我的functions.php (基于示例here)编写了这个脚本:
<?php
function enqueue_child_theme_styles() {
//deregister the parent bootstrap style and script
wp_deregister_style( 'bootstrap' );
wp_deregister_script( 'bootstrap' );
//enqueue my child theme stylesheet
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('theme') );
//enqueue bootstrap in the child theme
wp_enqueue_script('bootstrap-js', get_stylesheet_directory_uri().'/bootstrap/js/bootstrap.min.js', array('jquery'), NULL, true);
wp_enqueue_style('bootstrap-css', get_stylesheet_directory_uri().'/bootstrap/css/bootstrap.min.css', false, NULL, 'all');
}
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);它对我的页面模板非常有效,它现在响应于Bootstrap类.不幸的是,我网站上的其他事情也是如此。如果Wordpress试图加载我的页面模板,但在所有其他情况下忽略它,我如何使它适用?
发布于 2018-10-14 12:42:30
使用template
if (is_page_template($templatename))
{
wp_enqueue_script('bootstrap-js', get_stylesheet_directory_uri().'/bootstrap/js/bootstrap.min.js', array('jquery'), NULL, true);
...etc
}提供的链接有一个确切的例子,您正在寻找。
https://stackoverflow.com/questions/52802380
复制相似问题