Having issues Creating a Child Theme in WordPress - css

Hello I followed the steps on:
https://codex.wordpress.org/Child_Themes
and still no luck, the theme activates fine but the parent theme still remains fully active.
Style.css:
functions.php:
File Location & WP Editor:
Any help would be much appreciated thank you. Again the child theme does not seem to overwrite the parent theme dalton.

You shouldn't need to enqueue the parent theme's stylesheet in your child theme CSS - that should already be enqueued (and you may find, if you look in the source, that you've simply got two copies of the parent theme stylesheet in place).
Enqueue your child theme stylesheet like so:
add_action('wp_enqueue_scripts', 'my_the_enqueue_styles', 12); // Give this a lower priority so that it should be enqueued after the parent theme
function my_the_enqueue_styles() {
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css');
}
...then, in your child theme CSS, add something obvious like:
body {
background-color: purple;
}
...and you should see that the child theme stylesheet is loaded alongside your parent theme elements.
It's worth noting that get_template_directory_uri() will always refer to the parent theme, whereas get_stylesheet_directory_uri() will always refer to the currently-active child theme. If there is no child/parent theme and you're using a regular standalone theme, you can use these commands interchangeably.

Related

Wordpress - enqueue style after all others or after certain styles

I'm writing a plugin for Wordpress which I need to enqueue style files in front end. But when I do this some other plugins like vs_composer add their styles files after my plugin and override my codes. So I think there are two options to deal with this situation. First one is to make some CSS rules !important which I think is not a professional way. The other option is to load my plugin CSS files after all others; But is it possible?
I guess this goal is not achievable by using $deps parameter in wp_enqueue_style as it doesn't load files if dependency files don't exist.
You could enqueue your stylesheets by hooking into wp_head, which prints data in the head tag on the front end.
function enqueue_styles() {
wp_enqueue_style( 'frontend-style', plugin_dir_url( __FILE__ ) . 'styles.css' );
}
add_action( 'wp_head', 'enqueue_styles' ); // default priority: 10
If you need to output your stylesheets later, you can lower the priority.
For example,
add_action( 'wp_head', 'enqueue_styles', 20 );
Alternatively, you could change your selectors to be more specific, so your CSS rules take precedence over vs_composer's.
div {}
div.my-class {} /* more specific */
body div.my-class {} /* even more specific */
Specificity is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. […] Specificity is a weight that is applied to a given CSS declaration, determined by the number of each selector type in the matching selector. When multiple declarations have equal specificity, the last declaration found in the CSS is applied to the element.
— MDN source

WordPress - Child Theme not overriding the Parent's CSS

I have a child theme set up. I have a plugin WP-SCSS, I set directories and when I, I think, refresh the page, or maybe it's on save, but somehow the SCSS compiles to CSS. Great, but the issue is the css is not overriding the styles from the parent.
I'm using the bought theme Unicon. I am not sure why this is causing me issues, I don't want to have to keep writing !important on everything.
This is my style.css file:
/*
Theme Name: Unicon Child Theme
Description: Unicon Child Theme for your Customizations
Author: minti
Template: unicon
Version: 1.0
*/
#import url("css/main.css");
#import url("../unicon/style.css");
And my functions.php
<?php
function cls_scripts() {
// wp_enqueue_style( 'cls-css', get_stylesheet_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'cls_scripts' );
I'm not sure if it's the SCSS plugin causing this, worst case scenario I just don't use SASS and write everything into my style.css, thoughts?

Is there a way to set a stylesheet’s priority higher than !important?

I know I should not really ask this question, but before I get down voted to oblivion hear me out … I try to make the best out of a really bad situation:
My client has bought a WordPress theme and hired me to customize some parts of it. The bought theme is a a child theme and is a coding horror …
The theme’s stylesheet, tries to overwrite some styles from the woocommerce plugin, while the woocommerce stylesheet is loaded after the theme’s stylesheet. To do so it uses a crapload of !important declarations. I can not really fix any of this without breaking the theme update function.
So here is my plan: I want to add another stylesheet at the end, which overwrites all the mess, that has been done before. But simply putting it there would not overwrite all the !important declarations from the stylesheets before. So I was wondering if there is a way to prioritize my stylesheet above all the mess from before.
Any way to up my priority above the !important declarations are also appreciated!
You can either:
Ensure your declarations are equally specific but come later in the stylesheet:
div p strong {color:red!important}
div p strong {color:blue!important}
<section>
<div>
<p>lorem <strong>ipsum</strong></p>
</div>
</section>
Make your declaration more specific:
section div p strong {color:blue!important}
div p strong {color:red!important}
<section>
<div>
<p>lorem <strong>ipsum</strong></p>
</div>
</section>
See: https://css-tricks.com/specifics-on-css-specificity/ for some useful tips.
Normally with a child theme you would directly edit it. But if you are concerned about getting updates for the child theme, you could also deregister the crappy stylesheet and enqueue your own version from a plugin.
<?php
/*
Plugin Name: Fix Theme Stylesheets
Plugin URI: http://stackoverflow.com/q/33544364/383847
Description: Save me from these poorly coded marketplace themes
Version: 0.1-alpha
Author: helgatheviking
Author URI: http://kathyisawesome.com
*/
function so_33544364_custom_scripts() {
$theme = get_template();
if( ! is_admin() && 'your-themes-folder-name' == $theme ){
// get rid of the child theme's crappy stylesheet
wp_deregister_style( 'child-style' );
// optionaly load the parent theme directly instead of importing. can be better for minifying plugins
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
// load your improved stylsheet! style.css in the same folder as this plugin file
wp_enqueue_style( 'your-style', plugins_url( 'style.css', __FILE__ ) );
}
}
add_action( 'wp_enqueue_scripts', 'so_33544364_custom_scripts' );
!important is in 99% of cases a lazy way to obtain something that should be reached being more specific; specificity AND positioning are both keys elements, for instance:
p.foo { text-align: right; }
can be overwritten in this way:
body p.foo { text-align: left; }
Specificity is very important and it's the right way to go, here how you can calculate it:
link
ya you will try to using parent div..eg:-
.parent_div Child_div ul li{
margin: 0px;
}
this is way to Without using !important.parent div most be ist preroty rather than !important

Changes to style.css in Chrome workspaces not showing up

I've been trying to use Chrome Workspaces to edit the CSS in my WordPress child theme more efficiently. I followed the tutorial at http://wordimpress.com/using-chrome-devtools-workspaces-for-faster-wordpress-development/ to set it up. It works for the most part, when I edit any element in my child theme, the modification shows up instantly in my browser window and I can save it directly to the local style.css .
The problem occurs when I want to add a new element to my child theme (this element already exists in the parent theme but I did not need to modify it before, so it doesn't exist in the child theme). Using the inspect tool, I found the element in the parent style.css, then copied it over to my child theme editor (in the Source tab of devtools). But making any modifications to that element is not reflected in the live browser once I do that.
For instance, this was the original code in the parent style:
media="all"
.widget a {
color: #777;
}
And I copied this to my child stylesheet and changed it to color: #000 . But there is no change in the color seen in the live browser.
Am I doing something wrong?
If you are using Google Chrome do following
Go to Settings
Clear browsing data
Check all marks
Obliterate the past hour or day, depends on when it worked properly.
Click Clear browsing data
For me it worked.
add !important - to override existing css property
Hope it works
media="all"
.widget a {
color: #777;
}
Change this to
media="all"
.widget a {
color: #000!important;//change
}
It could be down to the cache-busting query string which WordPress adds-
Here is a relevant Chromium bug report.
For now, adding this to functions.php in WordPress in order to remove the cache-busting suffix allows me re-enable persistent edits:
function yourthemename_remove_version( $url ) {
return remove_query_arg( 'ver', $url );
}
add_filter( 'style_loader_src', 'yourthemename_remove_version' );
In future, it looks like Persistence 2.0, recommended at the end of the bug report, will be the solution. It can be enabled as a Chrome DevTool experiment now. Notice that Chrome Canary doesn't work in Linux yet.
Source: https://stackoverflow.com/a/42542366

removing inline styles in wordpress "recent comments" widget

I am working on a wordpress website and I am using _tk starter theme which is based on "Underscores" and Bootstrap.
I was styling the widget area from scratch, so I gave margin and padding = 0 to override bootstrap styles.
The problem is this worked for every widget except "Recent Comments" widget!
I checked it with developer tools and found that for recent comments widget ul and li, and inline style was forcing it to display some padding.
So I tried to search where this code is injected but failed to understand it. The ul id="recentcomments" and li class="recentcomments" reside in default-widgets.php
There is no style attribute assigned to these tags in that file. I tried searching in whole wordpress folder with folder search feature in netbeans but it does not show anywhere.
Here is the link to the screenshot. http://tinypic.com/r/efhwyt/8
It seems that there is a filter for removing this unwanted styles "show_recent_comments_widget_style"
in functions.php of my theme:
add_filter( 'show_recent_comments_widget_style', function() { return false; });
If you add the following to your style sheet should override the inline style.
.recentcomments
{
padding: 0 !important;
}
I got the answer and it is specific to tk theme only. Its Javascript -- . It was in bootstrap.wp.js file on line 26!
$( '.widget_recent_comments ul#recentcomments li' ).css( 'padding', '5px 15px');

Resources