How to enqueu php files with custom variable & conditionals?

From the enqueue point of view it doesn’t matter if it points to genuine static CSS file or endpoint that dynamically generates it. However there is a massive performance implication. Loading PHP engine (and worse — WordPress core on top) is much much more resource intensive than serving static file. Your end goal shouldn’t be … Read more

Enqueueing a script and a style sheet not working

In the context of parent – child themes, be aware that: The get_template_directory_uri() will give you the parent theme directory uri: https://codex.wordpress.org/Function_Reference/get_template_directory_uri. The get_stylesheet_directory_uri() will give you the child theme directory uri: https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri You are enqueueing parent-style with get_stylesheet_directory_uri(), which will give you the child theme directory uri. You are enqueueing child-css and child-js using … Read more

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

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