Last active
January 15, 2018 23:17
-
-
Save joelgriffith/48a2c5eb85a4b45db3c9d9950b416394 to your computer and use it in GitHub Desktop.
Find website titles (title, OpenGraph, schema.org)
This file contains hidden or 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
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