I want to use the WordPress JSON api to fetch content for a mobile app. I can iterate over the posts I receive – and I notice there is a “Rendered” field in the posts. I want to display that to the mobile user. Generally in a scrolling list view. However that rendered content is missing all styling CSS information. I’d like to embed that JSON API “rendered” content in web-views without fetching each of the whole posts like www.example.com/customtype/slug1 in WebView1 then the same for slug2 in WebView2 etc. I mean – I already fetched the content part – just missing the styles. Mobile data is precious 🙂
Is there a way to fetch the CSS information for a post in the active theme via the REST API? I tried caching style info in a global var as discussed in this SO answer (which I verified in debug). Then adding a custom REST endpoint to fetch the stuff I stored in that global variable. This almost works. The endpoint works. The data is cached after I display any post. However the global var in the child theme required to make this work appears to not be in the same scope as the plugin where I’m putting my rest to mobile stuff (that same global is always null/empty in the plugin).
My thoughts are now to make a custom post display in my child theme that just emits only the wp_head() stuff and I then fetch&cache that in the app – but that seems awkward. But I’m new to WP and PHP so – here we are. Thanks for any help!
Read more here: wordpress REST API – How to fetch style information?