wp_dequeue_style in Genesis framework not working - css

I wish to clean my code from duplicate css in my child genesis theme.
Some plugins use the same library with different version like font-awesome.
If you see html code here www.cartomanziadivinazione.it you can see:
<link rel='stylesheet' id='fontawesome-css' href='//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css?ver=1.3.9' type='text/css' media='all' />
I wish to delete this row and I wrote this in function theme
add_action('wp_enqueue_scripts', 'cleaning_seo');
function cleaning_seo() {
wp_dequeue_style( 'fontawesome-css' );
wp_deregister_style( 'fontawesome-css' );
}
but nothing...

According to codex:
Remove an enqueued script.
To be dequeued, the script must have been enqueued. Attempting to
dequeue a script before the script is enqueued will have no effect.
So, a possibility is you are trying to dequeue the script before it queued.
To make sure that you are using this function in the right place; try increasing the execution order:
add_action('wp_enqueue_scripts', 'cleaning_seo', 999);

Late, but maybe this answer will help others.
The handle has to be fontawesome, not fontawesome-css:
wp_dequeue_style( 'fontawesome' );
wp_deregister_style( 'fontawesome' );
The -css is added to the handle by WordPress (in the case of text/javascript -js is added).

Related

wp_enqueue_style() won't go away

I set up a child theme and enqueued the style.css file from the parent first, then I enqueued it from the child theme.
Everything is working fine!
All I wanted to do was disable the call to the child stylesheet, so I deleted the wp_enqueue_style( 'child-style',...) bit of code from the function and saved the file.
However, everytime I reload the pages the child theme style is still being called. I have stopped and started the server, but to no avail.
I am using XAMPP and I think there is some kind of server side caching going on, but I am not sure how to get it to update and refresh the function and not call the child stylesheet.
Any suggestions?
I tried renaming my function and only including the parent style like this:
function worker401k_enqueue_parent_styles() {
$parent_style = get_template_directory_uri();
// Enque the Parent styles
wp_enqueue_style( 'parent-style',
get_template_directory_uri() . '/style.css',
wp_get_theme()->get('Version'),
'screen'
);
}
// The third parameter is the priority
add_action( 'wp_enqueue_scripts', 'worker401k_enqueue_parent_styles', 10 );
I expected the call to go away, but no, it is still there!!
http://localhost/wp_1/wp-content/themes/twentynineteen-child/style.css?ver=0.0.1' type='text/css' media='all' />

How to remove or dequeue google fonts in wordpress twentyfifteen

I have created a child theme of twenty fifteen. I'd like to remove the google fonts loaded in wp_head but I can't get it to work. What is loaded is:
<link rel='stylesheet' id='twentyfifteen-fonts-css' href='//fonts.googleapis.com/css?family=Noto+Sans%3A400italic%2C700italic%2C400%2C700%7CNoto+Serif%3A400italic%2C700italic%2C400%2C700%7CInconsolata%3A400%2C700&subset=latin%2Clatin-ext' type='text/css' media='all' />
I've created a function.php in my child theme but I can't figure out how to remove this. I've gotten other things remove using:
remove_action('wp_head', '...');
But I can't figure out how to remove the fonts.
Also, any tips on how to remove the IE condition statements and css would be very helpful!
Thanks!
TwentyFifteen uses a custom function to build a Google fonts URL which is then used with wp_enqueue_style(). To remove Google fonts create a function in your child theme to dequeue the stylesheet.
Use the wp_enqueue_scripts hook and make sure to give it a higher priority than the hook in the parent theme. The default is 10 so in my example I use 20.
Example:
function wpse_dequeue_google_fonts() {
wp_dequeue_style( 'twentyfifteen-fonts' );
}
add_action( 'wp_enqueue_scripts', 'wpse_dequeue_google_fonts', 20 );
Deregister/Dequeue styles is best practice
https://codex.wordpress.org/Function_Reference/wp_deregister_style
https://codex.wordpress.org/Function_Reference/wp_dequeue_style
But you can use 'style_loader_src' filter too, to filter out styles with string condition, or other conditions, here is example for google fonts
add_filter( 'style_loader_src', function($href){
if(strpos($href, "//fonts.googleapis.com/") === false) {
return $href;
}
return false;
});
Open theme's functions.php and find a function called twentyfifteen_fonts_url() - it handles all the fonts stuff. In default file it starts on line 144. Edit it to your needs.
Other options:
Use a plugin to control fonts - https://wordpress.org/plugins/typecase/
Use a plugin to remove default fonts - https://wordpress.org/plugins/remove-open-sans-font-from-wp-core/
Use wp_deregister_style() function to manually unregister that stylesheet. See here.
As for the IE conditional - check the next function in functions.php, called twentyfifteen_scripts(). It starts on line 196.

Adding Modernizr properly to Wordpress?

This is my first time posting so any advice for how I post is much appreciated.
LINK TO SITE: http://rightbraingroup.com/services-new-css-style/
I am running into a problem trying to get this amazing css function to work - modernizr and the css to load in Wordpress. I tried many things like adding scripts to the header, registering and enqueing the modernizr.custom.js file. I also added . And none of these options worked. I am just learning about modernizr and am truly stuck. Any help is appreciated.
Below are the ways to include js and css into Wordpress without using Enqueing (which is the proper way).
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/modernizr.custom.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/component.css" media="screen" />
This is how I registered and Enqued the js file
// script manager template to register and enqueue files
function childtheme_script_manager() {
// wp_register_script template ( $handle, $src, $deps, $ver, $in_footer );
// registers modernizr script, stylesheet local path, no dependency, no version, loads in header
wp_register_script('new_service', get_stylesheet_directory_uri() . '/js/modernizr.custom.js', array('jquery'), false, false);
// enqueue the scripts for use in theme
wp_enqueue_script ('new_service');
}
add_action('wp_enqueue_scripts', 'childtheme_script_manager');
I keep getting a 404 error or "Resource interpreted as Script but transferred with MIME type text/plain" (used plugin to fix but did not help). If anyone can give a little guidance or direction it would be much appreciated. This is also my first time posting so if you need any more info from me please let me know. Thank you for your time.
Your wp_enqueue_scripts code is correct and Modernizr appears to be loading fine on your site. You need to do a similar invocation for adding stylesheets.
function childtheme_script_manager() {
wp_register_script('new_service', get_stylesheet_directory_uri() . '/js/modernizr.custom.js', array('jquery'), false, false);
wp_enqueue_script('new_service');
wp_register_style('my_style', get_template_directory_uri() . '/css/component.css', array(), false, 'screen');
wp_enqueue_style('my_style');
}
Note, I've left the $deps array empty, if the css has dependencies, you may need to specify those names in the array.

wordpress can't dequeue script/style that has query

Not sure if I worded it correctly but basically I wanted to load plugin CSS/JS on pages only that uses the actual plugins.. I have gotten a lot of it done by search thru the plugin files for any handles used in wp_enqueue_script within the plugins and simply wp_dequeue_script them in functions.php
However, there are some enqueues for style that include a .php and not a css file, for example.. in the plugin it enqueues a file
wp_enqueue_style("myrp-stuff", MYRP_PLUGIN_URL . "/myrp-hotlink-css.php");
so I've tried:
wp_dequeue_style('myrp-stuff');
wp_deregister_style('myrp-stuff');
It doesn't work
However, when the page/post is rendered it shows as
<link rel='stylesheet' id='myrp-stuff-css' href='http://www.modernlogic.co/wp/wp-content/plugins/MyRP/myrp-hotlink-css.php?ver=3.4.2' type='text/css' media='all' />
It addes -css to the id and it refuses to dequeue/deregister and be moved.
I have also tried the following with no luck
wp_dequeue_style('myrp-stuff-css');
wp_deregister_style('myrp-stuff-css');
Any suggestions?
Scripts and styles can be enqueued in any order and at anytime before wp_print_* actions are triggered. Which can make it difficult to remove them from the queue before output.
To make dequeue work consistently hook into into wp_print_styles or wp_print_scripts with a high priority, as this will remove the scripts and styles just before output.
For instance in your plugin loader code or template's functions.php file you could have a function and action hook like this:
function remove_assets() {
wp_dequeue_style('myrp-stuff');
wp_deregister_style('myrp-stuff');
}
add_action( 'wp_print_styles', 'remove_assets', PHP_INT_MAX );
Setting a high priority (third argument to add_action) when hooking into the action will help ensure that the callback remove_assets gets called last, just before scripts/styles are printed.
Note, while this technique is legitimate for removing scripts/styles it should't be used for adding assets. See this Wordpress Core blog post for more info.
Just to be sure, have you placed your code inside a function called by an action like this?:
add_action('wp_enqueue_scripts', 'dequeue_function');
function dequeue_function() {
wp_dequeue_style( array('myrp-stuff', 'myrp-stuff-css') );
wp_deregister_style( array('myrp-stuff', 'myrp-stuff-css') );
}

Wordpress: How to override all default theme CSS so your custom one is loaded the last?

I have a problem where I've been able to include a custom css in the section of my wordpress theme with the following code:
function load_my_style_wp_enqueue_scripts()
{
wp_register_style('my_styles_css', includes_url("/css/my_styles.css"));
wp_enqueue_style('my_styles_css');
}
add_action('wp_enqueue_scripts','load_my_style_wp_enqueue_scripts');
But the order in the source code is as follows:
<link rel='stylesheet' id='my_styles_css-css' href='http://...folderA.../my_styles.css?ver=3.1' type='text/css' media='all' />
<link rel="stylesheet" id="default-css" href="http://...folderB.../default.css" type="text/css" media="screen,projection" />
<link rel="stylesheet" id="user-css" href="http://...folderC.../user.css" type="text/css" media="screen,projection" />
I want my_styles_css to be the last file to load, overriding default and user files. I've tried to achieve this by modifying wp_enqueue_style in different ways, but without any success. I've tried:
wp_enqueue_style('my_styles_css', array('default','user'));
or
wp_enqueue_style('my_styles_css', false, array('default','user'), '1.0', 'all');
I've seen some related questions without answer or with these last 2 methods that are still failing for me.
The function above is part of a plugin that I've got enabled in my wordpress installation.
The add_action function has a priority parameter that might help:
$priority
(int) (optional) How important your function is. Alter this to make your function be called before or after other functions. The default is 10, so (for example) setting it to 5 would make it run earlier and setting it to 12 would make it run later.
Default: 10
http://codex.wordpress.org/Function_Reference/add_action
Or you could directly link to your css in your header.php file rather than using wp_enqueue_style, and therefore place it exactly where you want.
Otherwise there seems to be an answer here: How to force wp_enqueue_style to display CSS at the very bottom of the head tag to override all CSS rules?
The correct way to add a stylesheet to your theme is by way of the wp_enqueue_style() function:
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
With $deps you specify which stylesheets should be loaded before your custom stylesheet.
What about add_action('wp_head','load_my_style_wp_enqueue_scripts');?
Use wp_head instead of wp_enqueue_scripts.
Why not edit the theme?
You can do this from the Dashboard
Appearance -> Editor -> header.php
Just add your css last.

Resources