elegantthemes / Divi-Beta

8 stars 0 forks source link

How to Filter CSS Selectors in Exisiting Divi 5 Module #77

Open UmerCheema-WPD opened 4 months ago

UmerCheema-WPD commented 4 months ago

If we want to filter css selectors of divi module, we can achieve this in Divi 4 using add_filter('{module_slug}_css_selector', 'my_callback_function');

How can we achieve this in Divi 5.0? Is there any alternate hook for this?

Hook

apply_filters( "{$function_name}_css_selector", $selector )

Code Example

/**
 * Filter callback for modifying CSS selector of a specific module.
 *
 * @param string $selector The CSS selector used by the module.
 *
 * @return string Modified CSS selector.
 */
if (!function_exists('filter_module_css_selecto')):
    function filter_module_css_selecto($selector)
    {
        // Check if the selector contains '%%order_class%%'
        if (str_contains($selector, '%%order_class%% input.et_pb_s')) {
            // Add a custom class to the selector
            $selector .= $selector.' .custom-class';
        }

        return $selector;
    }

    add_filter('et_pb_search_css_selector', 'filter_module_css_selecto');
endif;