Skip to content

Instantly share code, notes, and snippets.

@denmch
Created June 4, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denmch/3941c26239accb661cff65bf9a60102e to your computer and use it in GitHub Desktop.
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.
/************************************************************************/
/* 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