Created
June 4, 2016 22:22
-
-
Save denmch/3941c26239accb661cff65bf9a60102e to your computer and use it in GitHub Desktop.
Bigcommerce doesn't give the option of setting a meta title different from post title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************************/ | |
/* Change title & metatitle for SEO using a data attribute on blog */ | |
/* posts in Bigcommerce. Embed the title within the post like this: */ | |
/* <span id="meta-title" data-title="This is a good SEO title!"></span> */ | |
/************************************************************************/ | |
$(document).ready(function() { | |
var newTitle = $('#meta-title').data('title'), | |
noMetaTitle = $('meta[name="title"]').length === 0, | |
hasDataTitle = newTitle !== undefined, | |
notACollection = $('body').hasClass('BlogPost'), | |
addMetaTitle = $('head').append('<meta name="title" content="' + newTitle + '"/>'), | |
pageIsBlogPost = noMetaTitle && notACollection && hasDataTitle; | |
if (pageIsBlogPost) { | |
document.title = newTitle; // Optional, if you prefer this for SEO or whatever | |
addMetaTitle; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment