Skip to content

Instantly share code, notes, and snippets.

@troutacular
Created January 11, 2017 21:34
Show Gist options
  • Save troutacular/4b6e04e2641e3fc23042e768d858ba95 to your computer and use it in GitHub Desktop.
Save troutacular/4b6e04e2641e3fc23042e768d858ba95 to your computer and use it in GitHub Desktop.
Javascript: Site Acronym for WordPress
// wrap the first word of the site title matching 'string' in a span to apply highlight color
function siteAcronymClass(acronym) {
var strTitle = document.getElementsByClassName('site-title')[0].innerHTML;
var newStrTitle = strTitle.replace(acronym, '<span class="site-acronym">' + acronym + '</span>');
if ( strTitle !== null ) {
document.getElementsByClassName('site-branding-title')[0].innerHTML = newStrTitle;
}
}
// Replace string value with acronym you want to wrap with a span class.
siteAcronymClass('Acronym');
// end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment