• Resolved Pavel Ciorici

    (@ciorici)


    Hello,

    Great plugin ??

    Quick question: is it possible to add a function in a theme so that people can select an existing CSS class without having to add them manually?

    For example, I want to create a theme with 3 different colors for widgets: red, blue and green, and I want these 3 additional styles/classes to be already registered by the theme once the plugin is installed.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Cindy Kendrick

    (@elusivelight)

    No, that’s not possible currently. I can add in a hook in the next version so that can be done. It’s a good idea ??

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @ciorici,

    I’ve added two new filters in the development version.

    widget_css_classes_default_settings
    This filter is only usefull for new websites (without pre-existing settings). It lets you set any setting from the start, overwriting the plugin default settings.

    widget_css_classes_set_settings
    This filter will overwrite the configuration you set in the admin so be carefull how you use it.
    In your case you can use it to append your theme CSS classes to the list of defined classes, like this:

    
    add_filter( 'widget_css_classes_set_settings', 'my_widget_css_classes_settings' );
    function my_widget_css_classes_settings( $settings ) {
        $theme_classes = array( 'red', 'blue', 'green' );
    
        // Append your classes.
        $settings['defined_classes'] = array_merge( $settings['defined_classes'], $theme_classes );
    
        // Or Prepend your classes.
        $settings['defined_classes'] = array_merge( $theme_classes, $settings['defined_classes'] );
    
        // Allways remove possible duplicates
        $settings['defined_classes'] = array_unique( $settings['defined_classes'] );
    
        // And return modified settings array
        return $settings;
    }
    

    You can already test the dev version if you want!
    https://github.com/cleverness/widget-css-classes/pull/22

    Regards, Jory

    Thread Starter Pavel Ciorici

    (@ciorici)

    @keraweb,

    Thank you a lot!

    Plugin Author Jory Hogeveen

    (@keraweb)

    Not a problem!

    I still need to test it on various installations and check if there are other issues that we can solve within this release but I hope to get it ready in short notice.
    I’ll mark this topic as resolved.

    Let me know if you have other ideas. And if you want, please consider leaving us a nice review after the new version is out and you have your themes all setup!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can I register several classes in my theme?’ is closed to new replies.