I am trying to enqueue a jQuery script to my Wordpress site but for some reason it is not adding. Below is my code I've added to my child theme's functions.php file.
<?php
function itm_adding_scripts() {
wp_register_script('my_amazing_script', '/wp-content/themes/italic-child/js/jQuery.equalHeights.js/js/jQuery.equalHeights.js', array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( '_enqueue_scripts', 'itm_adding_scripts' );
?>
You have a typo in the action missing wp prefix
Change
add_action( '_enqueue_scripts', 'itm_adding_scripts' );
To
add_action( 'wp_enqueue_scripts', 'itm_adding_scripts' );
Reference: wp_enqueue_scripts docs
You have a typo in your action. It should be wp_enqueue_scripts
add_action( 'wp_enqueue_scripts', 'itm_adding_scripts' );
Related
Remove CSS and JavaScript with a PHP function like this:
function disable_files() {
wp_dequeue_style('blocks');
wp_dequeue_style('library');
wp_dequeue_script( 'jquery-js' );
add_action('wp_enqueue_scripts', 'disable_files', 100); }
When I use this function in function.php nothing happens. Is there something missing in the script?
deregister was missing
function disable_files() {
wp_dequeue_style('blocks');
wp_dequeue_style('library');
wp_dequeue_script('jquery-js');
wp_deregister_style('blocks');
wp_deregister_style('library');
wp_deregister_script('jquery-js');
}
add_action( 'wp_enqueue_scripts', 'disable_files', 9999 );
add_action( 'wp_head', 'disable_files', 9999 );
I have a problem with removing JavaScript file in functions.php in WordPress.
This is the file I want to remove:
../js/scripts/wc/productFilters.min.js?ver=6.1.4' id='wd-product-filters-js'></script>
And this is my code. I put it on functions.php but it didn't work:
function dequeue_filter_js() {
wp_dequeue_script( 'wd-product-filters' );
wp_deregister_script( 'wd-product-filters' );
}
add_action( 'wp_enqueue_scripts', 'dequeue_filter_js', 1000 );
Thank You in Advance
I'd like to enqueue a stylesheet called charts.css & charts.min.css.
I'm not sure, why it's not working.
That's my added code in functions.php Wordpress:
function additional_stylesheets() {
wp_register_style( 'custom01', get_template_directory_uri().'/assets/css/minified/charts.min.css' );
wp_enqueue_style( 'custom01' );
wp_register_style( 'custom02', get_template_directory_uri().'/assets/css/unminified/charts.css' );
wp_enqueue_style( 'custom02' );
}
add_action( 'wp_enqueue_scripts', 'additional_stylesheets' );
I tried in elementor to style a table but nothin' happened.
So I also tried to use:
<link rel="stylesheet" href="wp-content/themes/astra/assets/css/minified/charts.min.css">
but that's also not working.
Did I make a mistake somewhere?
I use the theme astra in WordPress.
The path is wp-content/themes/astra/.
After appending styleheets in WordPress I do not have to call them in html code anymore am I right?
You don't need to register them. Instead use the following code:
function additional_stylesheets() {
wp_enqueue_style('charts_min_styles', get_theme_file_uri('/assets/css/minified/charts.min.css'), NULL, 1.2, false);
wp_enqueue_style('charts_styles', get_theme_file_uri('/assets/css/unminified/charts.css'), NULL, 1.2, false);
}
add_action( 'wp_enqueue_scripts', 'additional_stylesheets' );
The code goes to the functions.php of your active theme or child them.
I have a theme that defines a new post type but I want to remove that function in the child theme:
PARENT THEME FUNCTION:
add_action('init', 'portfolio_register');
function portfolio_register()
{
//post type definition
}
CHILD THEME FUNCTION:
This is what I tried but it is not working.
function child_remove_parent_function() {
remove_action( 'init', 'portfolio_register' );
}
add_action( 'init', 'child_remove_parent_function', 15 );
Anyone has an idea of what am I doing wrong?
Thanks in advance.
try this code before add action in child theme function.php
<?php
remove_action( 'init', 'portfolio_register' );
?>
or
<?php
add_action( 'after_setup_theme','remove_portfolio', 100 );
function remove_portfolio() {
remove_action( 'init', 'portfolio_register');
}
?>
I am working on the following code. I have looked at all the documents regarding wp_enqueue_scripts and wp_register_script I cannot get it my Wp_callApi.js to load.
How can I fix this?
<?php
/*
Plugin name: My webservice
Version: 1.4
Description: Calling Webservice with javascript.
Auther: JellyDevelopment
Author URI: http://jellydevelopments.co.za
Plugin URI: http://jellydevelopments.co.za
*/
add_action( 'wp_enqueue_scripts', 'load_Javascript' );
function load_Javascript() {
wp_register_script('prefix_script_01', plugins_url( 'Wp_callApi.js', __FILE__ ), array ('jquery'), "2.1", true );
}
//add_action( 'wp_enqueue_scripts', 'addMy_script' );
function addMy_script() {
wp_enqueue_scripts( 'Wp_callApi' );
}
add_action( 'woocommerce_payment_complete', 'addMy_script', 10, 1 );
?>
You have mutliple errors here. Try this version.
<?php
/*
Plugin name: My webservice
Version: 1.4
Description: Calling Webservice with javascript.
Auther: JellyDevelopment
Author URI: http://jellydevelopments.co.za
Plugin URI: http://jellydevelopments.co.za
*/
function load_Javascript()
{
wp_enqueue_script( 'prefix_script_01', plugins_url( '/Wp_callApi.js', __FILE__ ), array('jquery') );
}
add_action( 'wp_enqueue_scripts', 'load_Javascript' );
?>
This will precisely do what you want. It will enqueue a file named Wp_callApi.js to your front end. This file must be residing at the root of this plugin that you write. If you want to add this file to wordpress admin dashboard then you need to change the action. The last line will change to.
add_action( 'admin_enqueue_scripts', 'load_Javascript' );