Adding additional attributes to the tag
-
Greetings I have been playing around with the bootstrap framework for this test theme.
According to the “Introduction” page at Bootstrap, the CSS should be loaded with the following link tag”
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
There are 2 additional attributes in their CSS tag, “integrity” and “crossorigin.”
The WordPress enqueue function doesn’t seem to have any way to add custom attributes so I thought I would try a jquery solution using “document.getElementById() since the Bootstrap link tag has an ID of “bootstrap-css.”
$( document ).ready(function() { var strapatt = document.getElementById('bootstrap-css'); strapatt.setAttribute("integrity", "sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"); strapatt.setAttribute("crossorigin", "anonymous"); });
The file name is “bootstrap-attributes.js.”
The script is loading but it’s not adding the additional attributes.
Where am I going wrong on this?
The page I need help with: [log in to see the link]
- The topic ‘Adding additional attributes to the tag’ is closed to new replies.