首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对WordPress页面模板而不是整个站点的引导脚本和样式进行排队

问如何对WordPress页面模板而不是整个站点的引导脚本和样式进行排队
EN

Stack Overflow用户
提问于 2018-10-14 11:57:09
回答 1查看 1.5K关注 0票数 2

我是WordPress的新手,正在为我的网站构建一个单一的页面模板。我想保留我的主要WordPress主题为大多数网站,但我有一个非常具体的应用程序,我想使用引导带只在几页。为了避免在主题更新时丢失我的自定义工作,我用页面模板创建了一个子主题,然后从WordPress中为适当的页面选择了该模板。

最后,我为我的functions.php (基于示例here)编写了这个脚本:

代码语言:javascript
复制
<?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试图加载我的页面模板,但在所有其他情况下忽略它,我如何使它适用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-14 12:42:30

使用template

代码语言:javascript
复制
if (is_page_template($templatename))
{
wp_enqueue_script('bootstrap-js', get_stylesheet_directory_uri().'/bootstrap/js/bootstrap.min.js', array('jquery'), NULL, true);

...etc

}

提供的链接有一个确切的例子,您正在寻找。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52802380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档