【发布时间】:2018-10-14 21:18:39
【问题描述】:
我是 WordPress 新手,正在为我的网站构建一个单页模板。我想为网站的大部分内容保留我的主要 WordPress 主题,但我有一个非常具体的应用程序,我想在几个页面上使用 Bootstrap。为了避免在主题更新时丢失我的自定义工作,我使用页面模板创建了一个子主题,然后从 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 尝试加载我的页面模板时才适用,但在所有其他情况下忽略它?
【问题讨论】:
标签: wordpress twitter-bootstrap wordpress-theming custom-wordpress-pages