wp_dequeue_style not seems to working - wordpress

I'm build a wordpress theme and I've created in my style.css a custom class for the plugin: Social Count plus
The problem's that plugin use an own css called counter.css what I need to do is prevent the inclusion of this css, so I've inserted this line in my functions.php:
wp_dequeue_style( 'counter' );
unfortunately the style is even included during the site reload. What am I doing wrong?
Thanks.

Try this:
add_action('wp_enqueue_scripts', function() {
wp_dequeue_style('social-count-plus');
wp_deregister_style('social-count-plus');
});

Just leave the counter.css file in place but either empty it out or comment everything out. It can't load what's not there. Be aware though, and update to that plugin might add the contents of that file back.

Related

Woocommerce template not overriding

I am trying to override a woocommerce plugin but somehow it wont work.
In my custom theme I added the following in functions.php
function add_theme_wc_support() {
add_theme_support('woocommerce');
add_theme_support('woocommerce-composite-products');
}
add_action('after_setup_theme', 'add_theme_wc_support');
The directory for my template:
theme\templates\woocommerce-composite-products\single-product\template-file.php
I edited the template but nothing happened. I also tried to change the folder "woocommerce-composite-products" to just "woocommerce" but nothing.
My functions.php only contains the "add_theme_wc_support" function, so there cant be any conflicts.
How can I make this work?
Going by the comment you provided about how the plugin wants you to override the template your file path should look like this

Wordpress determine which file is enqueueing script

In my Wordpress site, the "pure css" (purecss.io) framework is included in my header, and I want to get rid of it. I'm sure it was included there in wp_enqueue_script(), but for the life of me I can't figure out which file or plugin included it to remove it!!
I created a new theme and deleted ALL other themes.
I downloaded the entire wp-content/plugins directory and performed a search on the whole folder for the yahooapis URL, found nothing.
Anyone know what my next step might be? I need to get rid of it because it's causing some of my new styles to be messed up, and it's included at the bottom of the list of scripts.
Thanks!
You try the wp_dequeue_script() function.
https://codex.wordpress.org/Function_Reference/wp_dequeue_script
function purecss_dequeue_script() {
wp_dequeue_script( 'pure-css' );
}
add_action( 'wp_print_scripts', 'purecss_dequeue_script', 100 );

Load CSS file into child theme Wordpress

I'm working on a child theme in Wordpress, I use this script to load my JS script in functions.php
function load_child_js() {
wp_enqueue_script( "main",get_template_directory_uri()."_child/scripts/main.js");
}
add_action( "wp_footer", "load_child_js");
I want to do the same for my css file, I try to reproduce the same script but it does not work.
Thanks for your help !
Use wp_enqueue_style for your css.
wp_enqueue_style('mycss',get_template_directory_uri().'_child/css/main.css');
Documentation
But instead of wp_footer, hook into wp_enqueue_scripts. You can also enqueue your script there, and if you want script to be in the footer, set 5th parameter to true. Documentation

Bootstrap/bootstrap-select issue with Wordpress plugin. (TypeError: $(...).selectpicker is not a function)

In Wordpres, I have created a plugin. I'm trying to use Bootstrap/bootstrap-select in order to create a multi-select (with checkboxes) on a custom page template, but I'm having problems. I'm not creating a new theme, but I am using a child theme. Here is what I've done:
Copied page.php from the parent theme to the child and renamed it to manage-matches.php
Edited the template and added
Template Name: manage matches
Created a new page and selected this new template
In the template loop content div, I call another PHP file using:
This function is in managematches.php and I've
I copied my header.php to the child and added the references to the bootstrap.css and the bootstrap-select.css
I've done
include_once 'includes/managematches.php';
in my plugin.
This function managematches() generates the html for my page and it works fine. In fact, I can create bootstrap elements so I know the bootstrap/bootstrap-select.css files are working. I've also created a .js file (managematches.js) and enqueued it and that is working. By working, I mean that standard jQuery functions and selectors work fine.
The problem is that I can't get any of the functions in bootstrap-select.js to work. I've tried putting the reference to it in a whole bunch of places, to no avail. I keep getting:
TypeError: $(...).selectpicker is not a function
The problem is described here: Bootstrap-select not working
and I know my issue is that I need to make sure bootstrap-select.js is included before loading my code.
What I'm not clear on is how to do this in the wordpress enviornment. I'm close, but not where I want to be. If anyone has a suggestion on how to resolve this, I would appreciate the help.
ANSWER
I enqueued the css and js in my plugin, but the functions.php would work too.
wp_enqueue_style( 'bootstrap', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css');
wp_enqueue_style( 'bootstrap-select', 'http://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.3/css/bootstrap-select.min.css');
wp_enqueue_script( 'bootstrapjs', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), '', true );
wp_enqueue_script( 'bootstrap-selectjs', 'http://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.3/js/bootstrap-select.min.js', array('jquery'), '', true );
The problem is described here: Bootstrap-select not working and I know my issue is that I need to make sure bootstrap-select.js is included before loading my code.
What I'm not clear on is how to do this in the wordpress enviornment. I'm close, but not where I want to be. If anyone has a suggestion on how to resolve this, I would appreciate the help.
I guess your javascript files are loaded either in the header.php or the footer.php on the main theme. Of course they can also be included in functions.php. You can inspect the source code of the generated page and check in which point is your bootstrap-select included and then search the name of the file on your theme's source code.
How did you enqueue your managematches.js?
By using wp_enqueue_script you can also declare dependecies of the enqueued script.

wp_enqueue_style not loading CSS

I am attempting to load a script using wp_enqueue_style following the advice on the Wordpres Codex, but the script doesn't seem to be included in the source. Is this the correct way to do it?
function load_scripts() {
wp_enqueue_style('bootstrap.css', get_template_directory_uri() . '/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'load_scripts');
Your action and function looks fine from here. The wp_enqueue_scripts hook should work perfectly for both stylesheets and scripts.
Have you tried echoing something out in the function to see if it's actually being called at all? I.e:
function load_scripts() {
echo "Does this output to the actual page?";
wp_enqueue_style('bootstrap.css', get_template_directory_uri() . '/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'load_scripts');
If it's not, you might have a problem with your placement of the code, but if you keep everything in functions.php and outside of any other scope this shouldn't be a problem.
Another thing that can cause this behaviour is if you have already registered a stylesheet or script with the same handle ("bootstrap.css" in this case). The first argument in the wp_enqueue_style() function is just a handle for internal dependency management and should be unique, try renaming it to something else and see if that fixes your problem.
Okay, first step is to ensure you are using the correct path of the CSS file.
Add the following line in the functions.php of your theme or other appropriate place.
print( get_template_directory_uri() . '/css/bootstrap.min.css' );
This should print the URL of your desired stylesheet on top of the page. Copy and paste this URL in a new tab, if it opens a stylesheet then you are good to go. Otherwise, there is a mistake in the path.
Second step is to ensure that wp_head() is being called on the page you are displaying. It can be placed in your header template or top of archives/post files etc. This function actually renders the styles and scripts on the page.
Without wp_head(), its basically useless to enque anything as you can add links and scripts manually if you know the exact paths.
Note that in admin mode there is a special hook 'admin_enqueue_scripts'. So, if there is need to load CSS in both modes, it should be done on two hooks.
function load_scripts() {
wp_enqueue_style('bootstrap.css', get_template_directory_uri() . '/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'load_scripts');
add_action('admin_enqueue_scripts', 'load_scripts');
You are trying to enqueue style on wp_enqueue_scripts hook.
Try wp_print_styles.
add_action('wp_print_styles', 'load_scripts');
Also try to register style, first.
in case you don't want to use wp_head(); in your template, you could also include your styles directly:
<link rel="stylesheet" href="<?php echo get_theme_file_uri( 'style.css' ); ?>">
beware though: wp_head() includes tons of stuff (scripts, styles,...), by wordpress itself as well as most plugins, so only omit it if you know what you're doing.
Register the style first:
function register_plugin_styles() {
wp_register_style('my-plugin', plugins_url('my-plugin/css/plugin.css'));
wp_enqueue_style('my-plugin');
}
http://codex.wordpress.org/Function_Reference/wp_register_style
Do that way. Dont try to enqueue directly. And put code into functions.php of course.
Fist confirm path of the css file is correct or not if is it a correct try with below code :
function load_scripts() {
wp_enqueue_style('load-custom-css-new', get_template_directory_uri() . '/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'load_scripts');
or Go with this URL.
https://developer.wordpress.org/reference/functions/wp_enqueue_style/
I had the same problem. Although I have implemented this many times before, I lost many hours to find out what went wrong with this.
Because I made my own themes, I had declared this file unit as “fuctions.php” (I lost the -n- letter).
So, besides all the things described above you should also consider, take a good look at the file name and confirm that is “functions.php” (not fuctions, not function etc).
This might be also the reason for you.
I had the same issue. I fixed it by hard refreshing the page with Ctrl + F5 to clear cache and the css loaded normally.
If you are protecting the directory with .htpasswd, the https call generated by get_stylesheet... will fail, and you might lose some time chasing that one.

Resources