The question title is self explanatory but, here it goes something else:
I need to add a small amount of CSS
rules to style a plugin but I need to do it in my Wordpress
functions.php
to avoid messing around with core files of that same plugin.
Is this possible, how?
CodePudding user response:
You do not need to "add style to the plugin," as a correctly configured WordPress installation will allow you to override the plugin CSS easily without interfacing with the plugin at all.
You should be using a WordPress Child Theme. You can add your CSS to the end of the child them style.css
file.
You can also include CSS through theme settings in some themes. Search for "Custom CSS [YourThemeName].
Or, you can choose one of many plugins that will permit you to configure custom CSS as well.
Finally, you could use one of many different approaches for including style with PHP.
I often use wp_add_inline_style for simple, brief CSS inclusions:
function add_some_custom_style(){
ob_start();
?>
.someclass {
somestyle: style;
}
<?php
$style = ob_get_clean();
if (! wp_style_is('some-custom-style-handle', 'enqueued')) {
wp_register_style('some-custom-style-handle', false );
wp_enqueue_style('some-custom-style-handle');
wp_add_inline_style('some-custom-style-handle', $style);
}
}
add_action('wp_head', 'add_some_custom_style');
CodePudding user response:
A safe way to add CSS to your plugin is to use wp_enqueue_style. And the easiest way is to echo it where you need it.
Refer this: https://wordpress.stackexchange.com/questions/255405/functions-php-inject-inline-css