WordPress.org

Ready to get started?Download WordPress

Forums

Set CSS attribute for widgets (8 posts)

  1. arjanver
    Member
    Posted 3 years ago #

    Hi,

    Is there a pluging or does someone have code to get the option to set a CSS class for widgets?

    For example in the admin panel i add widgets and i want there a custom field to add some css code to make the widgets background red and another widget blue.

    i've search but couldn't find such thing.

    anyone?

    thanks

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

  3. arjanver
    Member
    Posted 3 years ago #

    that is not what i mean.

    For example in the admin panel i add widgets and i want there a custom field to add some css code to make the widgets background red and another widget blue.

    so i define some background classes in the template css file.
    and i want a option to choose from the admin area to set the class.
    So i can easy change the background color for different sidebar boxes.

  4. ambrosite
    Member
    Posted 3 years ago #

    If you inspect the code generated by those widgets using a tool like Firebug, you will see that they are already being assigned unique CSS classes. For example, the div for the default Pages widget gets a class called "widget_pages". Just use the existing classes along with descendant selectors to style the widgets.

  5. arjanver
    Member
    Posted 3 years ago #

    no offence but you didn't understand my question ;)

    i know i can predefine these id's/classes, but that is not what i want.

    i want to change the background color of a widget from the widgets admin panel.

  6. ambrosite
    Member
    Posted 3 years ago #

    Why would you want to do that?

    To answer your question, no, it is not possible without rewriting the PHP code of the widgets. The code for the default widgets is in this file:

    /wp-includes/default-widgets.php

    Of course, hacking the core files is highly inadvisable, since all your hacks will be lost whenever you upgrade to a new WP version. What you should do instead is create custom widgets based on the default widget code, and then install them as plugins -- if you really want to take it that far. Personally, I think it would be much easier to style the widgets by editing the CSS file.

  7. zactoff
    Member
    Posted 2 years ago #

    Did you ever solve this? I want to do the same thing, got a lot of widget areas in the back end that I'd like to colour code for the client.

  8. arjanver
    Member
    Posted 2 years ago #

    no, sorry

Topic Closed

This topic has been closed to new replies.

About this Topic