I am creating a wordpress childtheme. I have style.css in the childtheme and I am using this:
wp_enqueue_style( 'parent-style-bob', get_template_directory_uri() . '/style.css' ); to bring in the style.css from the parent - 2016 in this case. This is working fine as far as I can tell.
I now want to add a separate responsive css style sheet that is AFTER my childtheme/style.css (for development purposes)
If I add this to my function wp_enqueue_style( 'responsive-bob', get_stylesheet_uri() . '/styles-responsive.css' ); it comes in BEFORE my childthemes css file.
How do i get the order right please?
Here's the whole function:
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style-bob', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'responsive-bob', get_stylesheet_uri() . '/styles-responsive.css' );
}
You can "wait" for the child style to load and then load your stylesheet, ie, make your stylesheet dependant on the child style. The child style handle will be twentysixteen-style
You can do the following
wp_enqueue_style( 'responsive-bob', get_stylesheet_directory_uri() . '/styles-responsive.css', array( 'twentysixteen-style) );
Related
I am pretty new to wordpress, I want to convert a bootstrap theme into wordpress,i dont know if this question is a stupid one. This is the code in my functions file
<!---This is my functions.php file---->
<?php
add_theme_support('post-thumbnails');
function new2w_theme_styles(){
wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '');
wp_enqueue_style( 'essentials_css', get_template_directory_uri() . 'assets/css/essentials.css');
wp_enqueue_style( 'layout_css', get_template_directory_uri() . 'assets/css/layout.css');
wp_enqueue_style( 'scheme_css', get_template_directory_uri() . '/css/color_scheme/blue.css');
wp_enqueue_style( 'custom_forms', get_template_directory_uri() . '/css/custom-forms-v2.css');
wp_enqueue_style( 'pack_css', get_template_directory_uri() . '/css/pack_realestate.css');
wp_enqueue_style( 'header-1', get_template_directory_uri() . '/css/header-1.css');
wp_enqueue_style( 'style_css', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'new2w_theme_styles');
function new2w_theme_js(){
wp_enqueue_scripts('bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js',array('jquery'), '', true);
wp_enqueue_scripts('script', get_template_directory_uri() . '/js/script.js', array('jquery'), '', true);
}
add_action('wp_enqueue_scripts', 'new2w_theme_js');
?>
Please how can I perform this same loop task for another section of my static page,I have looped through 3 images with this code, I have also created corresponding post in my admin panel;
<?php if( have_posts()) : while( have_posts()) : the_post();?>
HTML GOES HERE
<?php endwhile; endif;?>
<?
I want to use this same method to loop through another image grid of 4 with the get_the_post_thumbnail() function, how do I manage post for this.?
You could copy the contents of the bootstrap CSS file and paste the style definitions to your theme (in dashboard, go to Design / Customizer / Additional CSS and paste the code there).
However to apply the style classes to the correct WordPress generated DOM elements, you either have to apply class names to those DOM elements or rename the style classes such that they fit to the DOM elements' names. This approach could still clash with other CSS files anyways.
I register my css in Header with <link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri().'/style.css'; ?>">
and the site couldn't recognize my css file, I also tried to use enqueue style :
function my_assets() {
wp_enqueue_style( 'theme-style', get_stylesheet_uri(), array( 'style' ) );
wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_assets' );
and it recognize the css but when you edit the css file it is not changing/updating, so I deleted the enqueue_style function and now it recognizes 2 css and still not changing when you edit the css file.
what do you think is the problem and solution here?
Please try to use versioning when you enqueue the file.
wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/style.css', filemtime(get_stylesheet_directory() . '/style.css'), false );
On the official documentation, you can check the version parameters i used on this sample:
https://developer.wordpress.org/reference/functions/wp_enqueue_style/
Hope it helps.
Jose
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 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'm trying to convert HTML static website to WordPress. I'm stuck at the very beginning, where I need to load all my styles from css folder in my function.php
<?php
// Loading styles
add_action( 'wp_enqueue_scripts', 'load_styles' );
function load_styles() {
wp_enqueue_style( 'animate', get_template_directory_uri() . '/css/animate.css' );
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.css' );
wp_enqueue_style( 'font-awesome2', get_template_directory_uri() . '/css/font-awesome2.css' );
wp_enqueue_style( 'framework', get_template_directory_uri() . '/css/framework.css' );
wp_enqueue_style( 'owl', get_template_directory_uri() . '/css/owl.theme.css' );
wp_enqueue_style( 'style', get_template_directory_uri() . 'style.css' );
}
?>
Here are all my files located in the following directory:
And then I'm trying to inspect element in Google Chrome I got a bunch of errors that are saying the same thing: Failed to load resource: the server responded with a status of 404 (Not Found)
In my header.php I'm calling <?php wp_head(); ?> right before the </head> TAG. In my index.php file I'm calling <?php get_header(); ?>
I tried to move add_action( 'wp_enqueue_scripts', 'load_styles' ); to the bottom;
I tried to set permissions for my folders in Filezilla to 777;
I tried to use get_stylesheet_uri() instead of get_template_directory_uri();
And I don't know what I supposed to do next.
You've probably already figured this out but it looks like you missed /css/ before your style.css
It should look something like this:
wp_enqueue_style( 'style', get_template_directory_uri() . '/css/style.css' );