My folder for my child themes is well composed of a file 'style.css' and 'functions.php'
In my functions.php file I can not access my function theme_enqueue_styles() to use my custom css
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() .'/style.css' );
}
For the child theme, you need to replace get_template_directory_uri() to get_stylesheet_directory_uri().
The code should be:.
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_stylesheet_directory_uri() .'/style.css' );
}
Related
I am in a bit of a pickle, lol.
Here is my function:
function start_group_escapes_4_less() {
wp_enqueue_style( 'style', get_stylesheet_uri() . '/style.css');
wp_enqueue_script( 'ge4l', get_stylesheet_uri() . '/js/ge4l.js', array('jquery'), null, true);
}
add_action( 'wp_enqueue_scripts', 'start_group_escapes_4_less' );
Everywhere I checked, the syntax is right. Or is it?
Help :(
The function get_stylesheet_uri() return the url of the theme style.css file.
You need to use get_stylesheet_directory_uri()
function start_group_escapes_4_less() {
wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/style.css');
wp_enqueue_script( 'ge4l', get_stylesheet_directory_uri() . '/js/ge4l.js', array('jquery'), null, true);
}
add_action( 'wp_enqueue_scripts', 'start_group_escapes_4_less' );
Make sure the directory of the files style.css and ge4l.js are correct and appropriate to the wp-admin file. Or try puting ~ sign at the directory shown in your code.
Check the value of return => <?php echo get_stylesheet_uri(); ?>
Use get_template_directory() ?!
I'm trying to integrate js and CSS code elements in a twenty-seventeen WordPress theme. I use enqueue methods but it does not work, so suggest me to all about.
Write in function.php this code
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
I can't figure out what's wrong with my code. This is it so far:
function reg_scripts() {
wp_enqueue_style( 'bootstrapstylemin', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css' );
wp_enqueue_style( 'bootstrapstyleresmin', get_template_directory_uri() . '/bootstrap/css/bootstrap-responsive.min.css' );}
add_action('wp_enqueue_scripts', 'reg_scripts');
function wpbootstrap_scripts_with_jquery(){
wp_enqueue_script( 'custom-scriptes', get_stylesheet_directory_uri() . '/bootstrap/js/bootstrap.js', array('bootstrap-jquery'));
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );
I am sorry, there is a screenshot of the console
After I saw this errors, I removed the CDN's, but still not working.
try this;
function reg_scripts() {
wp_enqueue_style( 'bootstrapstylemin', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css', array(), '3.4.6' );
wp_enqueue_style( 'bootstrapstyleresmin', get_template_directory_uri() . '/bootstrap/css/bootstrap-responsive.min.css', array(), '1.0.0' );
}
add_action('wp_enqueue_scripts', 'reg_scripts');
function wpbootstrap_scripts_with_jquery(){
wp_enqueue_script( 'custom-scriptes', get_stylesheet_directory_uri() . '/bootstrap/js/bootstrap.js', array('bootstrap-jquery'), '3.4.6', false);
}
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );
I have a theme and a child theme and I am trying to load child theme blank css files to override the parent theme files rules.
In parent theme,, there is a style.css in theme root dir and there is responsive.css in /assets/css/ directory
In child theme there is style.css and responsive.css in child root directory
the functions.php has this code in it but the only thing that works is if I apply !important to child style css rules.
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/assets/css/responsive.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/responsive.css' );
}
How can I get my custom files to load AFTER the them main css files?
You can determine the load order by declaring dependencies. Note that all handles must be unique:
add_action( 'wp_enqueue_scripts', 'so27575579_enqueue_styles' );
function so27575579_enqueue_styles()
{
wp_register_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_register_style( 'parent-style-resp', get_template_directory_uri() . '/assets/css/responsive.css', array( 'parent-style' ) );
wp_register_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style-resp' ) );
wp_register_style( 'child-style-resp', get_stylesheet_directory_uri() . '/responsive.css', array( 'child-style' ) );
wp_enqueue_style( 'child-style-resp' );
}
I'm trying to link my WordPress Stylesheet to child theme at different directory/sub folder, it doesn't seems to work. Below are the code where I place it at functions.php
function theme_add_bootstrap()
{
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . 'assets/css/bootstrap.min.css' );
wp_enqueue_style( 'style-css', get_template_directory_uri() . 'assets/css/custom.css' );
wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . 'assets/js/bootstrap.min.js', array(), '3.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );
I try putting #import statement inside style.css, it doesn't work also.
Use this:-
function theme_add_bootstrap()
{
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );
wp_enqueue_style( 'style-css', get_template_directory_uri() . '/assets/css/custom.css' );
wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array(), '3.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );
Remember that get_template_directory_uri() will give you directory uri path with no /. SO you need to add / after this function.
Hope this will work for you.