Hello. Created a sitebar,

register_sidebar(array( 'name' => 'Widget', 'id' => 'widget-1', 'description' => 'first', 'before_widget' => '', 'after_widget' => '', 'before_title' => 'БдСсь иконка <h2>', 'after_title' => '</h2>', )); 

Before the tile, I insert an icon. Now the challenge is that this icon could change depending on the name of the widget. Suppose I put in the site bar VJ "Rubrics" I give him the title "Games" then the icon is automatically replaced with "Games", i.e. you need to write a condition somewhere (if "games" then ..). Or is it easier to make 10 sitebars? I would like to know how to do better

    1 answer 1

    It seems to me that it is better to edit before_widget and after_widget

     'before_widget' => '<div id="%1$s" class="widget-container %2$s">', 'after_widget' => '</div>', 

    And depending on the id, register the icon in the css via the pseudo-element :before

    As an option - you can put the plugin Widget CSS Classes, for example. And for each widget to write a specific class. Well, again css.

    For each widget, the default is still a wrapper. You prescribe her class. Let's say 'games icons'. In css write:

     .games:before{ background: url(ссылка Π½Π° ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ); } //ΠΈ ΠΎΠ±Ρ‰ΠΈΠΉ ΡΡ‚ΠΈΠ»ΡŒ для всСх ΠΈΠΊΠΎΠ½ΠΎΠΊ Ρ‚ΠΈΠΏΠ° .icons:before{ display: block; width: 25px; height: 25px; margin: 5px; } 

    This is for example, of course.

    • The fact is that this construction does not work. I have the latest version of WP. "% 1 $ s" is simply displayed in the code. And how about the option, let's say let's say 10 bars? Will there be any load, and so on? Just wanted to do something optimized or something. - KernelByte
    • 10 sidebars are just uncomfortable, in my opinion, di and unnecessarily. - Ivan
    • Try Widget CSS Classes. The best option, I think. - Ivan
    • Finished the answer a little. - Ivan
    • Thank you, but the fact is that I do everything without plug-ins, because there they cram everything that is needed and not needed, in the end I decided to do everything together without plug-ins, at least the main parts of the site. Ie if it can be done by hand, why should I download the plugin, where, along with the fact that I need, there are dozens of options. In other matters, I will somehow solve it without a plug-in, find a way to output the ID. - KernelByte