What is the proper way to include Bootstrap when executing a shortcode

I also find the typical practice of queuing globally or from inside shortcodes problematic. I had a similar challenge with implementing code highlight on my site — I only wanted scripts and style to load as necessary. I ended up checking content for <pre> tag as condition to output: {% if ‘<pre>’ in get_the_content() %} … Read more

functions.php How to add css/js depending on Template Name?

You can use wp_enqueue_style() before running get_header() in your blue.php file. If you’re looking for a way to do that inside your functions.php file, then the init hook is a bit too early for is_page_template(). Try the wp_enqueue_scripts hook instead: add_action( ‘wp_enqueue_scripts’, ‘load_my_theme_files’ ); function load_my_theme_files() { if ( is_page_template( ‘blue.php’ ) ) { wp_enqueue_style( … Read more

Parent theme CSS overriding child CSS rules

After looking at your parent theme’s source code related to enqueuing styles, the original code you posted looks close. You just need to use the handle from the parent theme, adios-main-style. Add wpse244754_child_theme_enqueue_styles() to your child theme’s functions.php file: add_action( ‘wp_enqueue_scripts’, ‘wpse244754_child_theme_enqueue_styles’ ); function wpse244754_child_theme_enqueue_styles() { // Enqueue the parent theme’s stylesheet wp_enqueue_style( ‘adios-main-style’, get_template_directory_uri() … Read more

Different ways to load child theme css

There’s nothing wrong with css rules ending up in your inspector twice. In many cases you want the first version, loading both parent and child styles. After all, in that case your child style sheet only needs to have the styles you want different from the parent. The browser will correctly apply the child rule … Read more

How can I add style sheet link to my wordpress page

Use wp_enqueue_style() in your functions.php: function custom_wp_enqueue_style() { wp_enqueue_style( ‘bootstrapcdn’, “https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css” ); } add_action ( ‘wp_enqueue_scripts’, ‘custom_wp_enqueue_style’ ); The second parameter can be the path to the folder in your server where you have your bootstrap.

Plugin CSS not enqueing

If you want to add inline CSS, use wp_add_inline_style(). <?php /** * Plugin Name: WPSE 257470 * Description: WordPress StackExchange question 257470 * Plugin URI: https://wordpress.stackexchange.com/questions/257470/ * Author: Nathan Johnson * Licence: GPL2+ * Licence URI: https://www.gnu.org/licenses/gpl-2.0.en.html */ //* Don’t access this file directly defined( ‘ABSPATH’ ) or die(); if( ! class_exists( ‘wpse_257470’ ) ): … Read more

Exclude external uri for css and js version

Declaring functions inside functions can lead to problems as explained here: https://stackoverflow.com/a/1631579/1228379 To solve the issue of remote files, you can use an additional parameter to indicate it is remote (or local) and call get_theme_file_uri/path accordingly. Alternatively, you can just call wp_enqueue_script/style directly and use standard version numbers, or simply save the files locally. In … Read more