How to change the rel through the filter of wp?

There is code that should replace the rel="stylesheet" to rel="preload" as="style" onload="this.rel="stylesheet":

if(!function_exists('add_rel_attribute_style')){function add_rel_attribute_style($tag,$handle){
 $handles=array('style', 'bootstrap');
 foreach($handles as $defer_script){if($defer_script===$handle){
 return str_replace('rel','rel="preload" as="style" onload="this.rel=\'stylesheet\'" rel',$tag);
 }}return $tag;}}

He does not change, and adds 2 rel:
<link rel="preload" as="style" onload="this.rel='stylesheet'" rel='stylesheet'

I would appreciate specific examples. In the code is not strong.
April 7th 20 at 15:35
0 answer

Find more questions by tags WordPress