Marek Čačko
Marek Čačko

Reputation: 1010

Add style for plugin setting page

I have done plugin for wordpress but I want to add twitter bootstrap css style into setting page for this plugin. My idea was add this code:

function my_plugin_admin_styles() {
    wp_register_style( 'bootstrap-style', plugins_url('style/bootstrap.min.css', __FILE__) );
    wp_enqueue_style( 'bootstrap-style' );
}

if (isset($_GET['page']) && $_GET['page'] == 'my_plugin') {
    add_action( 'admin_print_styles', array($instance, 'my_plugin_admin_styles'));
}

But it effects everything and it change menu on left side too. Is possible apply css only for my setting page?

Upvotes: 0

Views: 279

Answers (1)

robooneus
robooneus

Reputation: 1344

You would need to create a customized CSS file that targeted only things within your section of the plugin settings page. For example, you could build the plugin settings page with a wrapper like so:

<section id="mypluginidentifier-settings">
    <!-- all the plugin settings html here -->
</section>

Then, in the CSS, just prefix everything with #mypluginidentifier-settings. where mypluginidentifier = something unique to your plugin.

i.e.

#mypluginidentifier-settings .button {/*button styles*/}

Otherwise you will risk conflicting with the wordpress CSS.

This is really a big hassle, though, if you want to include all of bootstrap. I would also absolutely suggest you include your CSS locally within your plugin rather than calling to the hosted version of the file (you would have to, to do this, anyway).

Upvotes: 1

Related Questions