Skip to content

Instantly share code, notes, and snippets.

@joelgriffith
Last active January 15, 2018 23:17
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 joelgriffith/48a2c5eb85a4b45db3c9d9950b416394 to your computer and use it in GitHub Desktop.
Save joelgriffith/48a2c5eb85a4b45db3c9d9950b416394 to your computer and use it in GitHub Desktop.
Find website titles (title, OpenGraph, schema.org)
function getTitle() {
if (document.querySelector('meta[property="og:title"]')) {
return document.querySelector('meta[property="og:title"]').content;
}
if (document.querySelector('[itemprop="name"]')) {
return document.querySelector('[itemprop="name"]').text;
}
if (document.querySelector('title')) {
return document.querySelector('title').text;
}
return window.location.href; // Print URL as a fallback
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment