Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active April 15, 2024 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vanaf1979/c6d5628b4fc96946f6c95f3e79628d57 to your computer and use it in GitHub Desktop.
Save vanaf1979/c6d5628b4fc96946f6c95f3e79628d57 to your computer and use it in GitHub Desktop.
Fixing and Parsing WordPress Rest Api content in React. https://since1979.dev/fixing-and-parsing-wordpress-rest-api-content-in-react/
import React from "react";
import parse from "html-react-parser";
import Gist from "super-react-gist";
export default function WpApiContent(props) {
return parse(props.content, {
replace: (domNode) => {
if(domNode.name === "script" && domNode.attribs.src.indexOf("/gist.github.com/") ) {
return (<Gist url={domNode.attribs.src.replace(".js", "")} />)
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment