简体   繁体   English

使用functions.php将Bootstrap添加到Wordpress

[英]Adding Bootstrap to Wordpress Using functions.php

I have tried using the following code to embed Bootstrap to Wordpress but it doesn't work. 我尝试使用以下代码将Bootstrap嵌入到Wordpress中,但是它不起作用。 Need help.......... 需要帮忙..........

<?php  

 function resources() {

 wp_enqueue_style('style',get_stylesheet_uri());          
 wp_enqueue_style('bootstrap.min',get_template_directory_uri().'/css/bootstrap.min.css');
 wp_enqueue_style('bootstrap',get_template_directory_uri().'/css/bootstrap.css');
 wp_enqueue_style('bootstrap-theme.min',get_template_directory_uri().'/css/bootstrap-theme.min.css');
}     

add_action('wp_enqueue_scripts', 'resources');

This may be helpful to you 这可能对您有帮助

WordPress is to use wp_enqueue_style and wp_enqueue_script from within functions.php. WordPress将在functions.php中使用wp_enqueue_style和wp_enqueue_script。 In particular, we need to create a new function that adds (or enqueues) the css style and the js script and then allow WordPress to call it at the right moment by adding a wp_enqueue_scripts action. 特别是,我们需要创建一个新函数来添加(或加入)css样式和js脚本,然后允许WordPress通过添加wp_enqueue_scripts操作在适当的时候对其进行调用。

/* Add bootstrap support to the Wordpress theme*/

function theme_add_bootstrap() {
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css' );
wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array(), '3.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );

For Reference: click here 供参考: 单击此处

In order to wp_enqueue_scripts in function.php work properly, <?php wp_head(); ?> 为了使wp_enqueue_scripts中的wp_enqueue_scripts function.php工作, <?php wp_head(); ?> <?php wp_head(); ?> needs to be placed before the closing </head> and <?php wp_footer(); ?> <?php wp_head(); ?>需要放在结束</head><?php wp_footer(); ?> <?php wp_footer(); ?> before closing </body> tag in your template file. <?php wp_footer(); ?>然后在模板文件中关闭</body>标记。

Because you didn't post your template file, so I think this can be a reason causes your problem. 因为您没有发布模板文件,所以我认为这可能是导致您出现问题的原因。

Hope this help 希望这个帮助

Just use the bootstrap CDN - https://www.bootstrapcdn.com/ 只需使用引导CDN- https://www.bootstrapcdn.com/

In your child theme find the function theme_enqueue_styles() and add the two lines of extra code shown below. 在您的子主题中,找到函数theme_enqueue_styles()并添加以下两行额外的代码。

function theme_enqueue_styles() {
    // Add the following two lines //
    wp_enqueue_style( 'bootstrap-cdn-css', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
    wp_enqueue_script( 'bootstrap-cdn-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' );
    // ------               -------//
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') );
}

Make sure your file location of downloaded bootstrap files. 确保下载的引导程序文件的文件位置。 and put this code into functions.php 并将此代码放入functions.php

1.stylesheet CSS file 1.stylesheet CSS文件

2.script js file 2.script js文件

<?php

function load_stylesheets()

{

// enqueue parent styles

wp_enqueue_style('bootstrap', get_stylesheet_directory_uri().' /css/bootstrap.min.css');

wp_enqueue_script('bootstrap', get_stylesheet_directory_uri().' /js/bootstrap.min.js');

}

add_action('wp_enqueue_scripts','load_stylesheets');

?>

添加 HTML<div> 使用 WordPress 函数的元素内部.php</div><div id="text_translate"><p> 我想在 WordPress/Woocommerce 中的现有元素中添加一个带有 class 的 div。 我想让销售价格更漂亮:) 让我们从我现在拥有的开始:<a href="https://i.stack.imgur.com/3HYZ3.png" rel="nofollow noreferrer">在此处输入图片描述</a></p><p>代码:</p><pre> <ins> <span class="woocommerce-Price-amount amount"> <bdi> <span class="woocommerce-Price-currencySymbol">$</span>200.00 </bdi> </span> </ins></pre><p> 这就是我想要实现的目标:<a href="https://i.stack.imgur.com/gLnSQ.png" rel="nofollow noreferrer">在此处输入图片描述</a></p><p>代码:</p><pre> <ins> <span class="woocommerce-Price-amount amount"> <div class="vh-badge-ears"></div> <bdi> <span class="woocommerce-Price-currencySymbol">$</span>200.00 </bdi> </span> </ins></pre><p> 我最接近的是将这段代码添加到我的函数中。php:</p><pre> function bd_sale_price_html( $price, $product ) { if ( $product->is_on_sale() ): $return_string = str_replace( '<ins><span class="woocommerce-Price-amount amount">', '<ins><span class="woocommerce-Price-amount amount"><div class="vh-badge-ears"></div>', $price); return $return_string; else: return $price; endif; } add_filter( 'woocommerce_get_price_html', 'bd_sale_price_html', 100, 2 );</pre><p> 但是通过使用此代码,它看起来像这样: <a href="https://i.stack.imgur.com/yGorx.png" rel="nofollow noreferrer">enter image description here</a></p><p> 我希望这里有人可以帮助我。</p><p> 亲切的问候!</p></div> - Adding HTML <div> inside of element using WordPress functions.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加 HTML<div> 使用 WordPress 函数的元素内部.php</div><div id="text_translate"><p> 我想在 WordPress/Woocommerce 中的现有元素中添加一个带有 class 的 div。 我想让销售价格更漂亮:) 让我们从我现在拥有的开始:<a href="https://i.stack.imgur.com/3HYZ3.png" rel="nofollow noreferrer">在此处输入图片描述</a></p><p>代码:</p><pre> <ins> <span class="woocommerce-Price-amount amount"> <bdi> <span class="woocommerce-Price-currencySymbol">$</span>200.00 </bdi> </span> </ins></pre><p> 这就是我想要实现的目标:<a href="https://i.stack.imgur.com/gLnSQ.png" rel="nofollow noreferrer">在此处输入图片描述</a></p><p>代码:</p><pre> <ins> <span class="woocommerce-Price-amount amount"> <div class="vh-badge-ears"></div> <bdi> <span class="woocommerce-Price-currencySymbol">$</span>200.00 </bdi> </span> </ins></pre><p> 我最接近的是将这段代码添加到我的函数中。php:</p><pre> function bd_sale_price_html( $price, $product ) { if ( $product->is_on_sale() ): $return_string = str_replace( '<ins><span class="woocommerce-Price-amount amount">', '<ins><span class="woocommerce-Price-amount amount"><div class="vh-badge-ears"></div>', $price); return $return_string; else: return $price; endif; } add_filter( 'woocommerce_get_price_html', 'bd_sale_price_html', 100, 2 );</pre><p> 但是通过使用此代码,它看起来像这样: <a href="https://i.stack.imgur.com/yGorx.png" rel="nofollow noreferrer">enter image description here</a></p><p> 我希望这里有人可以帮助我。</p><p> 亲切的问候!</p></div> - Adding HTML <div> inside of element using WordPress functions.php WordPress在functions.php中添加简码 - WordPress adding shortcodes in functions.php 将javascript添加到wordpress functions.php - Adding javascript to wordpress functions.php 在functions.php中添加功能的问题[Wordpress] - Issue with adding function in functions.php [Wordpress] 将include添加到wordpress functions.php返回 - adding include into wordpress functions.php return wordpress functions.php - wordpress functions.php 使用在functions.php中定义的变量WORDPRESS - Using variables defined in functions.php WORDPRESS 在WordPress functions.php中使用POST参数 - Using POST parameters in WordPress functions.php Woocommerce wordpress functions.php-将php添加到div - Woocommerce wordpress functions.php - adding php to div 使用functions.php中的add_filter将类添加到Wordpress post_class - Adding a class to Wordpress post_class using add_filter in functions.php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM