I saw that someone had asked how to add attributes in script tag for 3rd party JS here: Adding Additional Attributes in Script Tag for 3rd party JS

My question is how to also make those attributes dynamic if I were to write a WordPress plugin that would take in a value that the user inputs via a widget.

The script_loader_tag filter only takes in 3 preset parameters ($handle, $tag, $src) so I can't figure out how to add in custom params to the $tag = str_replace( 'src=', 'data-attribute="'.$dynamicvar.'" src=', $tag ); from the parent function it's contained in.

Any help would be appreciated

Your Answer

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

Browse other questions tagged or ask your own question.