I am trying to find a way to dequeue styles and scripts on the "login, password reset and register " default wp pages.
I understand there is 'login_enqueue_scripts' but no such thing as login_dequeue_scripts.
Whats your approach ? Ive tried something like this:
add_filter('body_class', function($classes) {
if (in_array('login', $classes)) {
wp_dequeue_style( 'list-css' );
wp_dequeue_style( 'blog-css' );
wp_dequeue_style( 'dir-css' );
wp_dequeue_style( 'author-css' );
}
return $classes;
});```
You could just use the wp_dequeue_script/style function for the login_enqueue_script action. Like so:
function custom_login_page() {
wp_dequeue_style( 'list-css');
}
add_action( 'login_enqueue_scripts', 'custom_login_page' );
The action of 'login_enqueue_scripts' is what happens when the other scripts/styles are loaded on that page. You can create a custom function to run when that happens, which is what you want.
However, rather than dequeueing, why not just write some of your own CSS for the elements on the page, then enqueue whatever that custom CSS?
function custom_login_css() {
wp_enqueue_style( 'custom-login-styles', get_stylesheet_directory_uri() . '/custom-login.css' );
}
add_action( 'login_enqueue_scripts', 'custom_login_css' );
Here's a good reference for the different elements you can customize with CSS on the WP login page.
Related
I have a basic bunch of CSS/Js files defined in my functions.php file. There I register and enqueue those scripts and stylesheets.
But in specific situations I want to load additional scripts based on the site template which is used.
I tried to register and enqueue those additional scripts in the specific template file, but it didnt work. It does only work when included in the functions.php.
What is the correct way to do this?
You can try like this
add_action( 'wp_enqueue_scripts', 'enqueue_file' );
function enqueue_file() {
if(is_front() || is_archive()){ // you can set here condition
wp_enqueue_style( 'main-css', get_template_directory_uri() .
'/static/css/main.min.css"' );
}
}
add this to your functions.php in child theme:
add_action(
'wp_enqueue_scripts',
'loadActionFrontend'
);
function loadActionFrontend()
{
if( is_page( 'pageid here' ) ) {
wp_register_script(
'scriptName',
'scripturl',
[],
'',
true
);
wp_enqueue_script('scriptName');
}
}
with the query if( is_page( 'pageid here' ) ) you can insert your desired pageid where the script shold loaded.
I am trying to edit the styles of the Woocommerce checkout page that is coming from style.dev.css. I tried to copy the file to my child theme directory and made the changes in the new child file. However, it seems that the page is still loading the original file and not the theme file The reason I am not doing my edits in the style.css child file is that most selectors have !important and don't want to do heavy overwriting. Does anyone know what I am missing, please?
The documentation of WooCommerce could help you acheive what you are looking for.
WooCommerce - Disable the default stylesheet
Disable all stylesheets
WooCommerce enqueues 3 stylesheets by default. You can disable them all with the following snippet:
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
Disable specific stylesheets
If you want to disable specific stylesheets (i.e, if you do not want to include the handheld stylesheet), you can use the following:
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] );
unset( $enqueue_styles['woocommerce-layout'] );
unset( $enqueue_styles['woocommerce-smallscreen'] );
return $enqueue_styles;
}
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
Then enqueue your own stylesheet like so:
function wp_enqueue_woocommerce_style(){
wp_register_style( 'mytheme-woocommerce', get_stylesheet_directory_uri() . '/css/woocommerce.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'mytheme-woocommerce' );
}
}
add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' );
i have stylesheet that loads on all of my pages in my wordpress theme. i want to disable it in landing.php .
The file is in this address: http://example.com/wp-content/uploads/fusion-styles/fusion-22528.css
i had tried these codes so far:
function themeslug_enqueue_style() {
if (is_page_template( 'landing.php' )) {
wp_enqueue_style( 'stylesheet', 'http://example.com/wp-
content/uploads/fusion-styles/fusion-22528.css', false );
}
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
and this one:
function se_remove_styles() {
if ( is_page_template( 'landing.php' ) ) {
wp_dequeue_style( 'http://example.com/wp-content/uploads/fusion-
styles/fusion-22528.css?timestamp=1510985246&ver=4.9' );
}
}
add_action( 'wp_print_styles', 'se_remove_styles', 99999 );action(
'wp_print_styles', 'se_remove_all_styles', 999999 );
but didnt worked. i had use this code:
function se_remove_all_styles() {
global $wp_styles;
if ( is_page_template( 'landing.php' ) ) {
$wp_styles->queue = array();
}
}
add_action( 'wp_print_styles', 'se_remove_all_styles', 99 );
but it will remove all of my styles.
any help will appreciated.
This code snippet removes queued CSS called "animate" from your WP frontend.
function se_remove_styles() {
wp_dequeue_style( 'animate' );
}
add_action( 'wp_enqueue_scripts', 'se_remove_styles',99999 );
So, how to get handle name of queued CSS? There are some ways to do it, here is one of them:
Go to view-source:yourwebsite.com
CTRL+F and find your needed CSS file.
You will see the line like this:
< link rel="stylesheet" id="fusionblabla-css" href="http://example.com/wp-content/uploads/fusion-styles/fusion-22528.css" type="text/css" media="all" />
You see id='fusionblabla-css' there. Then "fusionblabla" is the handle name you are looking for. (not 'fusionblabla-css', but "'fusionblabla')
After it is done and you make sure that it is working you can add condition to that function
function se_remove_styles() {
if (SOME CONDITION HERE)
wp_dequeue_style( 'animate' );
}
add_action( 'wp_enqueue_scripts', 'se_remove_styles',99999 );
I was trying to include a css file in my WordPress plugin admin page. I have tried below method
function theme_name_scripts() {
wp_enqueue_style( 'jspro', '/includes/parts/css/jspro.min.css');
}
But unfortunately it doesn't work. My css file path is correct as given here,and I have tried almost every method. Any idea?
You need to have an absolute URL to your css file, and hook into the correct admin hook (in this case, 'admin_init'):
add_action( 'admin_init', 'theme_name_scripts' );
function theme_name_scripts() {
wp_enqueue_style( 'jspro', plugins_url('includes/parts/css/jspro.min.css', __FILE__));
}
In admin mode there is a special hook 'admin_enqueue_scripts' that WP reccomends to use.
add_action('admin_enqueue_scripts', 'theme_name_scripts');
function theme_name_scripts() {
wp_enqueue_style('jspro', '/includes/parts/css/jspro.min.css');
}
Also, hook can also be used to check the name of current admin page:
function theme_name_scripts( $hook ) {
if ( $hook != 'edit.php' )
return;
wp_enqueue_style('jspro', '/includes/parts/css/jspro.min.css');
}
I am trying to dequeue the following plugin scripts:
function afg_enqueue_cbox_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('afg_colorbox_script', BASE_URL . "/colorbox/jquery.colorbox-min.js" , array('jquery'));
wp_enqueue_script('afg_colorbox_js', BASE_URL . "/colorbox/mycolorbox.js" , array('jquery'));
}
I tried adding this in functions.php:
add_filter('wp_print_styles', 'remove_mycred', 100);
function remove_mycred() {
wp_dequeue_script( 'afg_colorbox_script' );
wp_dequeue_script( 'afg_colorbox_js' );
}
But it does not work at all - both scripts are still there.
There are other scripts that I have no problems dequeuing - just not those.
I suspect jquery has something to do with my problems?
thanks!
Blaise
You have two problems here, you should use wp_enqueue_scripts hook to hook your function to. Secondly, you will need to go and look at the priority which the author used to enqueue these scripts, and then give your action hook a lower (higher number) priority. Your code should look something like this
function remove_mycred() {
wp_deregister_script( 'afg_colorbox_script' );
wp_dequeue_script( 'afg_colorbox_script' );
wp_deregister_script( 'afg_colorbox_js' );
wp_dequeue_script( 'afg_colorbox_js' );
}
add_action( 'wp_enqueue_scripts', remove_mycred, 9999 );