Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

deleted 62 characters in body
Source Link
drake035
  • 3k
  • 50
  • 138
  • 264

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

EDIT: As per this suggestion, I tried to extract the script tag from the post and re-inject it into the DOM. But, it still doesn't work. Actually even when simply loading my Gist script into a variable then injecting the content into the DOM, it doesn't work. Yet it works with any other script, for example this this:

const tag = document.createElement('script');
tag.src = 'https://fabricepallaudmy-site.com/test.js';
document.querySelector('body').prepend(tag);

But the exact same snippet using instead my Gist URL fails to execute.

Why don't Gist scripts execute when injected into the DOM?

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

EDIT: As per this suggestion, I tried to extract the script tag from the post and re-inject it into the DOM. But, it still doesn't work. Actually even when simply loading my Gist script into a variable then injecting the content into the DOM, it doesn't work. Yet it works with any other script, for example this:

const tag = document.createElement('script');
tag.src = 'https://fabricepallaud.com/test.js';
document.querySelector('body').prepend(tag);

But the exact same snippet using instead my Gist URL fails to execute.

Why don't Gist scripts execute when injected into the DOM?

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

EDIT: As per this suggestion, I tried to extract the script tag from the post and re-inject it into the DOM. But, it still doesn't work. Actually even when simply loading my Gist script into a variable then injecting the content into the DOM, it doesn't work. Yet it works with any other script, for example this:

const tag = document.createElement('script');
tag.src = 'https://my-site.com/test.js';
document.querySelector('body').prepend(tag);

But the exact same snippet using instead my Gist URL fails to execute.

Why don't Gist scripts execute when injected into the DOM?

Notice removed Draw attention by Community Bot
Bounty Ended with no winning answer by Community Bot
added 661 characters in body
Source Link
drake035
  • 3k
  • 50
  • 138
  • 264

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

EDIT: As per this suggestion , I tried to extract the script tag from the post and re-inject it into the DOM. But, it still doesn't work. Actually even when simply loading my Gist script into a variable then injecting the content into the DOM, it doesn't work. Yet it works with any other script, for example this :

const tag = document.createElement('script');
tag.src = 'https://fabricepallaud.com/test.js';
document.querySelector('body').prepend(tag);

But the exact same snippet using instead my Gist URL fails to execute.

Why don't Gist scripts execute when injected into the DOM?

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

EDIT: As per this suggestion , I tried to extract the script tag from the post and re-inject it into the DOM. But, it still doesn't work. Actually even when simply loading my Gist script into a variable then injecting the content into the DOM, it doesn't work. Yet it works with any other script, for example this :

const tag = document.createElement('script');
tag.src = 'https://fabricepallaud.com/test.js';
document.querySelector('body').prepend(tag);

But the exact same snippet using instead my Gist URL fails to execute.

Why don't Gist scripts execute when injected into the DOM?

Notice added Draw attention by drake035
Bounty Started worth 200 reputation by drake035
Source Link
drake035
  • 3k
  • 50
  • 138
  • 264

GitHub Gist embedded in a WordPress post fetched through WP REST API

After adding an embedded Gist in my WP post, all I see when fetching it through REST API is the embed code, meaning <script src="https://gist.github.com/username/b5f6f2d0xxxxxxxdf9c90cbede0e.js"></script>.

There are solutions to properly render an embedded Gist in WordPress but these solutions work on a WordPress site, not on a non-WP site merely fetching posts from WP.

Any idea how to solve this issue?

default

AltStyle によって変換されたページ (->オリジナル) /