What is the best way to provide plugin users with a way to customized the styles

I’m working on a plugin to be release to the public, it is a very simple plugin that includes a single html element in the page html.
I can do many things to allow users customize its appearance:
1. Let them override a default CSS that is includes as a plugin configuration (on a management screen)
2. Require that they modify their styles.css (not a very good idea for this plugin)
And probably a fee more

option 1 seems like the most user Friendly, since it allows any admin to modify the style without need of accessing code. But I wonder if there might be a better way?

Read More

Is it possible to provide a default CSS file for the plugin that would be theme independent and would be editable through a management screen? The styling needs to persist regardless of chosen theme.

Any thoughts?

Related posts

Leave a Reply

1 comment

  1. Is it possible? Yes.

    Option 1

    Simply register and enqueue your default stylesheet. The theme stylesheet can then be used to override whatever styles you implemented.

    function register_my_styles() {
        wp_register_style( 'default-style', plugins_url('default.css', __FILE__) );
        wp_enqueue_style( 'default-style' );
    }
    add_action( 'wp_enqueue_scripts', 'register_my_styles' );
    

    Option 2

    Register whatever custom options you need either on a specific plugin options page or using the WordPress Settings API. Then output these styles in a regular old script block in the theme header.

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