I am using a JSON API plugin for wordpress to allow me to work with the sites content in a phonegap application I'm building.
However due to the complexity of some of the content on the site (caused by shortcodes outputting graphs, sliders etc..) these aren't suitable to be displayed in the mobile app. I need to remove the shortcodes from the JSON output.
I have found that I can hook into the_content
filter in wordpress and use remove_shortcode
to take out the necessary shortcodes. But the problem is I can only do this when I access the json url via my browser.
For example, I may use http://example.com?json=1
to return recent posts. If I type this in my url bar I can parse the url, determine that json=1
is there and strip the shortcodes.
However when I am doing an ajax (JSONP) request from my mobile application, it doesn't appear to be able to check the url for the json
parameter, thus my shortcodes are not being stripped. I can't even pass in any headers either as they won't make it because of the nature of JSONP
requests I believe.
Has anyone got any ideas as to how I can figure out when a JSON request from my mobile application is received, so that I can then remove the shortcodes?
Something like
if(is_json()){
//remove shortcodes
}
And before it's brought up, I have asked this on the Wordpress Stackexchange but to no avail
Update: Here is the code I use for the ajax request from the mobile app
$.ajax({
url: "http://www.example.com/?json=1",
dataType: "jsonp",
async: true,
success: function(result) {
app.populate(result)
},
error: function(request, error) {
alert('Network error has occurred please try again!');
}
});