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:
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.
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
版权声明:本文标题:shortcode - Get Required Assets (JS, CSS etc) for post using REST API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741291396a2370568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论