我是WordPress的新手,正在为我的网站构建一个页面模板。我想保留大部分站点的主要WordPress主题,但是我有一个非常特定的应用程序,我希望仅在几个页面上使用Bootstrap。为了避免主题更新时丢失自定义工作,我使用页面模板制作了子主题,然后从WordPress中为相应页面选择了该模板。
我终于为我找到了这个脚本functions.php
(基于此处的示例):
<?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尝试加载我的页面模板但在其他所有情况下都忽略它时才应用此方法?
if (is_page_template($templatename))
{
wp_enqueue_script('bootstrap-js', get_stylesheet_directory_uri().'/bootstrap/js/bootstrap.min.js', array('jquery'), NULL, true);
...etc
}
提供的链接提供了您要查找的确切示例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句