• Erik

    (@southernutahautism)


    I recently discovered that you can add a individual class to any menu item in the custom menu backend, and it will appear in that menu entries class tag on your website. Pretty awesome.

    I have long wondered if there was a way to do this for widgets. Often, I have a widget of some sort that I want to style in a unique way, but I have to add the widget, and then go to the website and see what ID WP has assigned it, for instance a text widget might be assigned:

    id="text-3"

    But if you were to style the widget based on this ID, and then move the site to a new location, such as having a development install and a production isntall, the widget ID may be different.

    Is there any plugin available that adds a little ID field to each widget so you can style them on a individualized basis, without having to publish the widget first and see what WP assigned to it?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Also, if you’re moving from development to production installs, I recommend migrating the whole database along with all the files. This way things like widget id’s and post id’s won’t change.

    More information: http://www.billerickson.net/how-to-move-your-wordpress-website/

    Thread Starter Erik

    (@southernutahautism)

    How bizarre that after about 15 minutes of google searching, I never ran into that plugin.

    I am in a situation where I don’t have the access to do the migrations myself, so often I have to do workarounds so other people in other departments. So the more I can take out of the equation, the better.

    Thanks for pointing this out.

    Thread Starter Erik

    (@southernutahautism)

    Well, this plugin appears to conflict with the “Widget Context” plugin and is throwing errors to the log.

    Probably out of my league to try and figure out what the conflict is.

    here’s what I get

    20110225T185945: www.XXXXXXXXX.com/wp-admin/widgets.php
    
    PHP Fatal error:  [] operator not supported for strings in /XXXXXXXX/wp-content/plugins/widget-context/widget-context.php on line 146

    Tried it on another site that doesn’t use the Widget Context plugin, and it seemed to work. Might have to see what is up with this with someone who knows more about PHP than me.

    You could also use jQuery in some instances. I had a project where we wanted a different widget title color depending on which position they were in. So first widget has a blue title, second one a red… I used jQuery to apply classes to these rather than installing Widget Classes.

    <script type="text/javascript">
    jQuery(function() {
    	jQuery( "#sidebar h4.widgettitle:eq(0)").css("color", "#f9f284");
    	jQuery( "#sidebar h4.widgettitle:eq(1)").css("color", "#d6e7a1");
    	jQuery( "#sidebar h4.widgettitle:eq(2)").css("color", "#f2acb5");
    });
    </script>
    Thread Starter Erik

    (@southernutahautism)

    Okay the “Widget Classes” plugins is bogus. I haven’t been able to consistent get it to not fatal-error anywhere I’ve isntalled it.

    What I want is just a way to add an ID to the top level of the widget item, so that I can use the specificity of CSS to customize just 1 or 2 widgets based on need. It goes beyond just changing the color of the title bar. Often I want widgets to change their border widget heading style, font, just whatever.

    I think I might have to look into developing a plugin on my own for this.

    Twig

    (@palpatine1976)

    I agree w/ Erik – the Widget Classes plugin was fine for older versions of WP, or those that didn’t have other widget plugins installed. However if you are using anything new (like Widget Cache) then the Widget Classes plugin breaks.

    I think it is because the Widget Classes plugin dev didn’t namespace his/her functions, so calling new Widget.whatever() causes conflicts. Shame because it did exactly the simple task I needed… adding a custom CSS class to a specific widget instance.

    For adding a custom class to a widget all you need is either KC Widget Enhancements or ZigWidgetClass and if you need to control where your widgets appear then you can’t do better than Widget Logic. As of this posting only ZigWidgetClass works with Widget Logic out of the box. The KC plugin needs a small change in order for it to work. They have been alerted as to the fix and will probably release it soon.
    The main diff between the two is Zig only adds a custom class while KC adds both custom ID and custom Class.

    Twig

    (@palpatine1976)

    @hallmarc – thanks for the tip! I’m using ZigWidgetClass now and no issues seen yet.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding class to a widget, similar to custom menus – plugin for this?’ is closed to new replies.