Wordpress Plugin CSS style sheet shows up correctly in some themes but not others - css

I'm writing a custom wordpress plugin, and am trying to enqueue the plugin's CSS style. Currently testing in my local WP instance.
The styling is partially working in the Twenty Twenty Two theme (the dashicons are showing correctly, style doesn't work),
is not working in the Twenty Twenty theme (neither dashicons nor style are showing up),
but it is working properly in the Twenty Twenty One theme.
Here is the code:
function comment_rating_styles() {
wp_register_style( 'comment-rating-styles', plugins_url( '/' , __FILE__ ) . 'assets/style.css');
wp_enqueue_style( 'dashicons' );
wp_enqueue_style( 'comment-rating-styles' );
}
add_action( 'wp_enqueue_scripts', 'comment_rating_styles' );

It may be possible that something in the theme overwrites or disables the dashicons or the comment styles. You can try to add a higher priority, so it gets executed later.
add_action( 'wp_enqueue_scripts', 'comment_rating_styles', 999 );

Related

How properly enqueue a child theme

I've been trying to develop a simple child theme to tweak a few things on my website which currently uses the vantage theme. So far, I've had little success.
The two files (style.css and function.php) I've created only have a few lines of code, but I'm still unable to pinpoint the problem.
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles',
PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-style',
get_template_directory_uri().'/style.css' );
}
?>
/*
Theme Name: vantage-child
Template: Vantage
*/
body {
color:aqua;
}
I suspect the problem is with the enqueueing in the PHP file, but all configurations that I have found on the internet and the wordpress codex don't seem to work on my site. When I activate the child theme created by my code, the site reverts to ONLY the styles in my child theme's stylesheet, instead of falling back on the parent theme's stylesheet when no styles are specified in the child theme.
For child theme you can first need to create folder with themename-child.
Then you have to create style.css file.
Put the following lines in your style.css
/*
Theme Name: Twenty Fourteen Child
Theme URI: http://yourwebsite.com/twentyfourteen-child/
Description: My first child theme, based on Twenty Fourteen
Author: Joshi Niket
Template: twentyfourteen
Text Domain: twenty-fourteen-child
*/
Then create functions.php in child theme folder and put the following code.
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>
Please check following link to make child theme with proper steps, i have added few here to guid you.ReferenceLink
Thank you ,I hope this helps you.
Please install and create child theme by using One-Click Child Theme
plugin. This is very easy to use

Wordpress theme alter order of stylesheets

I've followed these two links of a "tutorial" to set up a WP page with the use of git and composer.
https://deliciousbrains.com/storing-wordpress-in-git/
https://deliciousbrains.com/using-composer-manage-wordpress-themes-plugins/
My question:
By looking at the network tab of the developer tools on chrome I see that the bootstrap stylesheet gets called as last one, and so its overwrite the theme styles and my child-theme styles.
But I want the following order:
first: bootstrap styles, second parent-theme styles, and third child-theme styles.
How do I accomplish that goal without touching the parent-theme directly?
Or do I get something wrong and this order, as it is now is intended?
You have to use dependency parameter of wp_enequeue_style function : Filenames are used as example, please change according to your need.
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
/** Enqueue scripts and styles. **/
function mytheme_scripts()
{
wp_enqueue_style( 'bootsrap-styles', get_template_directory_uri() . '/css/bootstrap.min.css','', 'v1' );
wp_enqueue_style( 'main-css', get_template_directory_uri() . '/css/main.css',['bootsrap-styles',''], 'v1' );
}
You can do this through your theme's functions.php
add_action('wp_enqueue_scripts', function(){
wp_enqueue_style('mainstyle', get_template_directory_uri() . '/main.css' );
}, 99);
Wordpress will place the stated .css file in your header and giving a 99 priority, which means it will add it later than the rest. You can do this for each of the desired .css files and maintain your own preferred order.

Wordpress ?ver=### not loading the latest child-theme styles sheet

I have WordPress theme with a child theme. After editing and saving the child style sheet, I don't see the changes. Looking at the source code, the style sheet is loaded but has this ver at the end: style.css?ver=4.9.7
Now, the styles show when I load style.css but shows an empty file with comments (the original file when first got the theme) style.css?ver=4.9.7
I understand that it is encouraged to have custom styles in the child theme but, then why doesn't WordPress support this?
Any advice or help is appreciated. Thanks.
This version added on function.php file, check it first
Better enqueue style on function.php like this
function child_themes_styles() {
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array(), wp_get_theme()->get('Version'));
}
add_action( 'wp_enqueue_scripts', 'child_themes_styles' );

Adding custom header and footer to wordpress blog

here I have a site, tinywolf.uk that i'm currently working on. The homepage is a static site separate from wordpress, but the blog part of the site http://www.tinywolf.uk/blog will be powered by wordpress.
Im currently using the twenty-fifteen theme, and would like to have the header and footer from the homepage in the blog as well for continuity.
So far I have created a child theme, and then a new header.php file which contains the header from the homepage. This replaces the existing wordpress header.php and displays correctly, however, the styling for the rest of the theme has disappeared. I want to maintain the styling for the posts.
How do I call the correct styling from the twenty-fifteen theme to ensure that the content (blog posts) are correctly styled?
here is my code for the child-theme header.php
I have tried including the style.css for the twenty-fifteen theme using <link rel="stylesheet" and although this brings up some of the formatting it also breaks the structure of the page.
here is the content of my functions.php:
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/blog/wp-content/themes/twentyfifteen/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/blog/wp-content/themes/twentyfifteen/style.css',
array('parent-style')
);
}
?>
and this is my child style.css:
/*
Theme Name: Tiny Theme Child
Theme URI: http://example.com/twenty-fifteen-child/
Description: Twenty Fifteen Child Theme
Author: Joel S
Author URI: http://www.tinywolf.uk/blog
Template: twentyfifteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-fifteen-child
*/
you have to link parent theme style.css in your child theme.
Here is a good example from codex
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
codex
If I understood true, you want to have your static page header and footer on your wp.
The only thing you need is make a copy of both parts from your static page put on separate files named header.php and footer.php then change the codes as title code to become dynamic WP codes.
After that call them into your theam.
But,
If you want using child theme do like this:
Follow all steps above and named your files as e.g. header-child.php & footer-child.php then call them like this: <?php get_header('child'); ?>
remember: header and footer must be first of your files name you cannot make like child-header.php. would not works.

change order of css files in header

I am creating a child theme for an existing theme. When setting up I noticed a few layout changes for the child theme cf the parent theme. Eventually I have worked out that this is due to the header pulling in the css files in a different order.
In the parent it goes:
pile of css files
theme styles.css
In the child them it goes:
theme styles.css
pile of css files
child styles.css
I want to get the order in the child them same, but just have the child one added on at the end,
In my child functions.php I have this.
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
I have tried adding an large index to the end of the add_action call but that just messes things up even more.
So, how can I get the files in the right order please
Your add_action function has a 'priority' argument you can use
http://codex.wordpress.org/Function_Reference/add_action
you can pass an arg on add_action for priority like
add_action( 'wp_enqueue_scripts', 'pile_name_scripts', 5 );
With 5 being loaded before the default priority of 10.

Resources