Create custom css box for a wordpress plugin

I have looked all over the web for a tutorial or code on how to create a custom css textfield for a plugin. Would really appreciate if someone could help. Thanks!

Related posts

2 comments

  1. ok bro lets do it

    in plugin main file you must register setting for css field

    Like:

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

    And then in your settings file where you create setting 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 your template under the get_header();

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

    or you can add in header in plugin main file 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 will help you 🙂

  2. It depends on where you’re trying to put the custom CSS box.

    • Inside the customizer
    • On it’s own settings page
    • Inside a widget

    More info would let me help answer the question better.

Comments are closed.