Widget:Meta
From The Observatory
<script>
updateMetaTags({ title: , description: , canonical: , focus_keyword: , keywords: });
function updateMetaTags({ title, description, canonical, focus_keyword, keywords }) { if (title) { document.title = title; }
if (description) { let metaDesc = document.querySelector('meta[name="description"]'); if (!metaDesc) { metaDesc = document.createElement('meta'); metaDesc.setAttribute('name', 'description'); document.head.appendChild(metaDesc); } metaDesc.setAttribute('content', description); }
if (canonical) { let linkCanonical = document.querySelector('link[rel="canonical"]'); if (!linkCanonical) { linkCanonical = document.createElement('link'); linkCanonical.setAttribute('rel', 'canonical'); document.head.appendChild(linkCanonical); } linkCanonical.setAttribute('href', canonical); }
if (focus_keyword) { var focusKeyword = focus_keyword; let metaFocus = document.querySelector('meta[name="focus_keyword"]'); if (!metaFocus) { metaFocus = document.createElement('meta'); metaFocus.setAttribute('name', 'focus_keyword'); document.head.appendChild(metaFocus); } metaDesc.setAttribute('content', focusKeyword); }
if (keywords) { var keywordList = keywords; let metaKeys = document.querySelector('meta[name="keywords"]'); if (!metaKeys) { metaKeys = document.createElement('meta'); metaKeys.setAttribute('name', 'keywords'); document.head.appendChild(metaKeys); } metaDesc.setAttribute('content', keywordList); } } </script>