admin管理员组

文章数量:1277286

I'm using the REST API to access WordPress data and publish it on a custom frontend as part of an integration.

This works great because the shortcodes are parsed and rendered by WordPress so the content field returned from the API includes the shortcode HTML rather than the shortcode itself.

The issue is that most of the shortcodes require some JS and CSS to properly function, but this is not included by the REST API. An example of this would be a form plugin that usually includes some CSS to style the form and some JS to validate and process the form.

The system doesn't use a fixed set of plugins so I can't just hardcode references to the assets.

My question is this: how can I get the required assets (js, css) for a post when accessing it via the REST API?

I have 2 ideas and I'm not confident or proud of either:

  1. Send a separate HTTP request to the post view URL and try to extract the content directly from the HTML. This will be slow and prone to error.

  2. Build a REST API feature that can be given a post ID and return the required assets. Again, this is another HTTP request and I woudl like to avoid that if possible.

Also, I'm aware of the cross domain XML issues I may face when these plugins try to make AJAX requests, but I will get around this using Access-Control-Allow-Origin on the WP server.

本文标签: shortcodeGet Required Assets (JSCSS etc) for post using REST API