I have the following in the child theme functions.php:
add_action('wp_enqueue_scripts', 'helloooo');
function helloooo(){
wp_enqueue_script( 'my_js', get_stylesheet_directory_uri() . '/js/scripts.js', array('jquery') );
}
yet scripts.js is not getting called. I've been at this forever and am at my wits end so any help is greatly appreciated!
Site: http://www.bridgechurchbr.com/
Related
I'm absolutly new to wordpress theme development and I am having some issues
enqueuing my javascript file.
// Enqueue script
wp_enqueue_script( 'personaltheme-script', get_template_directory_uri() . '/dist/assets/js/bundle.js', array(), '1.0.0', true);
}
add_action( 'wp_enqueue_scripts', 'personaltheme_script');
What am I doing wrong here? My styling seams to work so far:
function personaltheme_style(){
wp_enqueue_style( 'personaltheme-stylesheet',
get_template_directory_uri() . '/dist/assets/css/bundle.css',
array(), '1.0.0', 'all');
}
add_action( 'wp_enqueue_style', 'personaltheme_style');
Does anybody know how to solve this problem?
Thanks in advance!
Try to register your script before:
function az_register_script(){
// Register script
wp_register_script('personaltheme-script', get_template_directory_uri() . '/dist/assets/css/bundle.css', 'array()', '1.0.0', true);
// Enqueue script
wp_enqueue_script( 'personaltheme-script' );
}
add_action('wp_enqueue_scripts', 'az_register_script');
I Hope it helps!
I am having trouble with including modernizr for wordpress. I am using a child theme, btw. Can anyone help me out?
function foundation_assets() {
// Load JavaScripts
wp_enqueue_script('add_jquery', 'http://code.jquery.com/jquery-latest.min.js');
wp_enqueue_script('new_jquerypp', get_stylesheet_directory_uri() . '/js/jquerypp.custom.js');
wp_enqueue_script('bookblock', get_stylesheet_directory_uri() . '/js/jquery.bookblock.js');
//wp_enqueue_script('extra', get_stylesheet_directory_uri() . '/js/extra.js');
wp_enqueue_script('include_modernizr', get_stylesheet_directory_uri().'/js/modernizr.custom.js');
//Load Stylesheet
wp_enqueue_style( 'bookblock-css', get_stylesheet_directory_uri() . '/css/bookblock.css' );
}
add_action( 'wp_enqueue_scripts', 'foundation_assets' );
Here is my code for enqueuing it. It is saved in the functions.php.
Edited: Code has been changed.
1) it's commented out
2) you are missing the closing parathesis.
wp_enqueue_script('include_modernizr', get_stylesheet_directory_uri().'/js/modernizr.custom.js');
Also take a look at the function definition to ensure your scripts will load in the right order https://developer.wordpress.org/reference/functions/wp_enqueue_script/
for example wp_enqueue_script('new_jquerypp', get_stylesheet_directory_uri() . '/js/jquerypp.custom.js', array('add_jquery')); will make sure that new_jquerypp loads after jQuery itself
I trying to create some admin pages for tutorial for WordPress. I have added standard css and js files with function that is wp_enqueue_style. It worked, but in enqueue.php file, commands doesn't work.
My codes in enqueue.php:
<?php
function theme_load_admin_scripts($hook){
if('toplevel_page_theme_option' != $hook){
return;
}
wp_register_style('theme_admin', get_template_directory_uri() . '/css/theme.admin.css', array(), '1.0.0', 'all');
wp_enqueue_style('theme_admin');
wp_enqueue_media();
wp_register_script('theme-admin-script', get_template_directory_uri() . '/inc/js/theme.admin.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('theme-admin-script');
}
add_action('admin_enqueue_scripts', 'theme_load_admin_scripts');
?>
use admin_init
add_action('admin_init', 'theme_load_admin_scripts');
https://codex.wordpress.org/Plugin_API/Action_Reference/admin_init
I just realized that my site has not been using the local files of bootstrap and was getting theme via CDN. I've now been trying to figure out how to switch from CDN to using the local files, but every time I attempt to switch them my whole site becomes messed up. I have the bootstrap css files in a css folder as well as the js files in a js folder. Can anyone help me get bootstrap from my local files?
This probably seems like an easy question however I'm still pretty new at this, so I'm completely lost.
what I had before in my functions.php...
function learningWordPress_resources() {
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', array('jquery'), '3.3.7', true );
wp_enqueue_style( 'bootstrap-style', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
}
add_action('wp_enqueue_scripts', 'learningWordPress_resources');
what I tried to switch it too...
function learningWordPress_resources() {
wp_enqueue_style( 'bootstrapstyle', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'bootstrapthemestyle', get_template_directory_uri() . '/css/bootstrap-theme.min.css' );
wp_enqueue_script( 'bootstrap-script', get_template_directory_uri() . '/js/bootstrap.min.js', array(), true );
}
add_action('wp_enqueue_scripts', 'learningWordPress_resources');
I think you need to load three files: css, javascript, and your local style.css file:
Here is what I do on my Legal Firm Website - you can view the source yourself.
function btc_scripts() {
wp_enqueue_style( 'bootstrap-style', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '3.3.5' );
wp_enqueue_style( 'btc-style', get_template_directory_uri() . '/style.css' , array ('bootstrap-style'),'1.0.1');
wp_enqueue_script ( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '3.3.5', false);
}
add_action( 'wp_enqueue_scripts', 'btc_scripts' );
I want to load jquery files using wp_enqueue_script in wordpress. below is the code in my function.php file, which is not working, can anyone mention where is the error, thanks
function load_myfiles() { // load external file
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery-1.11.1.min.js' );
wp_register_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.js' );
wp_enqueue_script('jquery'); // enqueue the external file
wp_enqueue_script('bootstrap-js'); // enqueue the external file
}
add_action( 'wp_enqueue_scripts', 'load_myfiles' );