Create a custom css field for wordpress plugin

I looked around the web for a tutorial or code on how to create a custom CSS text box for a plugin. It would be very helpful if someone could help. Thanks!

+4
source share
2 answers

ok bro lets do it

in the main file of the plugin you must register the setting for the css field

how

register_setting('settings-group', 'css_field');

And then in your settings file, where you create the settings form (e.g. setting.php)

<textarea cols="50" rows="20" name="css_field" id="css_field" tabindex="1"><?php echo get_option('css_field') ?></textarea>

Then call it in the template under get_header();

<style type="text/css">
    <?php echo get_option('css_field'); ?>
</style>

or you can add a header to the main file of the plugin. Like:

function wp_css_custome(){
?>
    <style type="text/css">
        <?php echo get_option('css_field'); ?>
    </style>
<?php
}
add_action('wp_head','wp_css_custome');

Hope this helps you :)

+1
source

It depends on where you are trying to place the custom CSS block.

  • Inside customizer
  • On your own settings page
  • Inside widget

.

+1

Source: https://habr.com/ru/post/1610587/


All Articles