0

So I want my website to have an opengraph preview. For that I coded a new system in my index.html file which goes like this:

$(document).ready(function(){
  $("#navbar").load("navbar.html");
  $("#header").load("header.html");
});

And then the navbar loads here in a div:

<div id="navbar"></div>

The navbar works fine, but the header is having some issues. I put the header here before the <head> ends:

<div id="header"></div>

I tried doing this as the code for the header:

<!-- HTML Meta Tags -->
<title>M100</title>
<meta name="description" content="Thing">

<!-- Facebook Meta Tags -->
<meta property="og:url" content="https://micamaster100.github.io/">
<meta property="og:type" content="website">
<meta property="og:title" content="M100">
<meta property="og:description" content="Thing">
<meta property="og:image" content="https://opengraph.b-cdn.net/production/images/6956cfb8-f271-4cc5-bea6-965c7ce33b70.png?token=UTylE3SBRlkQmuQGqlHtvBVjJSbd8Wh6iZV5TvXLWF0&height=675&width=1200&expires=33258560618">

<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="micamaster100.github.io">
<meta property="twitter:url" content="https://micamaster100.github.io/">
<meta name="twitter:title" content="M100">
<meta name="twitter:description" content="Thing">
<meta name="twitter:image" content="https://opengraph.b-cdn.net/production/images/6956cfb8-f271-4cc5-bea6-965c7ce33b70.png?token=UTylE3SBRlkQmuQGqlHtvBVjJSbd8Wh6iZV5TvXLWF0&height=675&width=1200&expires=33258560618">

<!-- Meta Tags Generated via https://www.opengraph.xyz -->

And only get the title but not the social media preview.

edit: looking at the website now does have the social media preview, but I added the opengraph directly into the index.html. My goal here is to have that in a seperate script.

1
  • 1
    <div> elements cannot go inside <head>
    – Phil
    Commented Aug 2 at 1:38

1 Answer 1

0

Open Graph parsers typically do not execute JavaScript and thus will never see tags you're loading via AJAX requests or generating client-side.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.