• I developed a widget and the widget looks exactly like the other widgets in the website, so it inherits style, etc.

    Problem is, this particular widget needs a little edit: I should change the color of the title and of the title background.

    At the moment, I print the title this way:

    if (!empty($title)) {
                        echo $args['before_title'] . $title . $args['after_title'];
                    }

    I suppose (not tried) that $args['before_title'] and $args['after_title'] are responsible for generating this HTML:

    <div class="widget-main-title">
    <h4 class="widget-title"> (TITLE) </h4>
    </div>

    Now, if so, I could simply echo e new version of this HTML and reference other custom CSS classes.

    But is this brutal way the way to go or is there something neater I could do?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The args come from the theme, in its call to register_sidebar.
    https://developer.www.ads-software.com/reference/functions/register_sidebar/
    This function has a filter for the defaults, but most themes would specify what they want, so most defaults are not used.

    The styles your widget has is from using the same classes as the other widgets. This is not a bad thing. But there are additional classes put on each one, unfortunately, they have the instance number, so it is different for every site.

    If this is simply for your own site, you can of course do whatever you want, including ignoring the theme’s before and after markup, or styling the class for that instance of the widget.
    But if you are distributing your widget for others to use, it’s best to use standard practice of making them all look alike. (play nice with the theme, since “looks” is the theme’s job)

    Thread Starter islp

    (@islp)

    @joyously It’s not something I must redistribute. The widget is part of a plugin I created: the plugin displays reminders tailored on users (so, from the admin area I can decide to show/hide textual reminders for a particular users).

    Since the reminder is displayed only for a week once every three months && the widget MUST be noticed, it should stand out in some way. I initially placed it on top of every other widget, but I found this was not enough.

    Thanks for your kind reply

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom title and background title for widget’ is closed to new replies.