0

I want to override some rules of a plugin css file within my own theme so next time that I updated that plugin, my settings of that plugin be in a safe place . currently I copied that css file into my theme and changed some rules.So then I need to override this rules. I think found an answer that is related to my question (HERE) but I can't understand this code. how it works?

add_filter( 'style_loader_src', 'wpse106104_replace_stylesheet', 10, 2 );
function wpse106104_replace_stylesheet( $stylesheet_src, $handle ){
   if( 'plugin-script-handle' == $handle ){
        $stylesheet_src = get_template_directory_uri() . '/css/themes-copy-of-plugin.css';
   }
return $stylesheet_src;
}
  • It replaces the src paremeter (url of the css file) with another one. What don't you understand exacly? – cybmeta Aug 10 '15 at 18:22
  • Yes, it's right. But I'm trouble with how it know which one of the plugins I want to override on it? (apologies for my bad English) – Mehran Aug 10 '15 at 20:07
  • It checks the plugin's handler, plugin-script-handle in this case. The handler is the first parameter of wp_enqueue_style() used to enqueue the stylesheet. – cybmeta Aug 11 '15 at 8:12
  • I'm post it as a question so you can mark this topic as resolved and other users can find the answer easier. – cybmeta Aug 11 '15 at 16:28
1

The style_loader_src filter is used to modify/filter the src (url) of a stylesheet. The function callback accepts two parameters, the first is the original src and the second the handler of the stylesheet. The handler is the first parameter of wp_enqueue_style() used to enqueue the stylesheet.

So, to replace a stylsheet source with another one you should check the handler to know wchich stylesheet it must replaced, in the code you posted the checked handler is plugin-script-handle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.