简体   繁体   中英

Using javascript to read HTML from a wordpress page

We have an application in AngularJS and a wordpress website, and whenever we do a release we update the 'release notes' page on the wordpress website with everything that has been updated (usually a video and some text).

I need to start pulling the content of that page into the application so the users would see the release notes there as well, i tried using iframe but putting an entire page in an iframe just doesn't look good, so I'm wondering, is there a way I can fetch the HTML from that page on the wordpress website and render it in the AngularJS application?

The solution is to use WP's API to get the content of the page: https://developer.wordpress.org/rest-api/reference/

After getting the content you may want to filter out the wordpress/theme tags, you can do that through wordpress by using the standard text editor or you can have some regex on the javascript side:

var exp = /\[[^\]]*\]/g;
latestReleaseNotes.content.filtered = latestReleaseNotes.content.rendered.replace(exp,'');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM