2

i'm working in android application that use wordpress rest api to get blog from website to , i don't have any knowledge about php or wordpress , but i take some time to learn about it , any way my problem is on the json .the content contain paragraphs unknown and i don't know how to solve this problem ,please help android application json youtube video

2

The content that you are referring to is coming from the Elegant Themes Page Builder plugin on that site.

The page builder uses WordPress Shortcodes to render the content on the WordPress site. However, when you use the REST API, the content is pulled from the WordPress database and the shortcodes are not processed/rendered first.

You would need to remove the shortcodes from the returned JSON before it is displayed in your app. You could use something like this to remove the shortcodes before displaying your content in the app:

// Remove Divi/ET Page Builder shortcodes
$content = preg_replace('/\[\/?et_pb.*?\]/', '', $content);
  • +1, but no, the rest api returns what it should return, the post_content, if you are not happy with it you should develop your own end point – Mark Kaplun Apr 14 '18 at 8:04
  • ( post edited) if i try to hide them i will lost youtube video – monsieur Moumni Apr 15 '18 at 22:06
  • Then to need to write a function to parse the YouTube videos too then – Mat Apr 15 '18 at 23:17
  • thinks guys it fix by adding the redix on jquery function because i dont have access to wordpress admin dashboard content_splited= content.replace(/\[\/?et_pb.*?\]/g,'@');' – monsieur Moumni Apr 22 '18 at 16:03
0

You can place this code in your themes functions.php file:

function awh_filter_post_json( $data, $post, $context ) {
    $data = json_encode($data); //convert array or object to JSON string
    $data = preg_replace('/\[\/?et_pb.*?\]/', '', $data); //remove shortcodes
    $data = json_decode($data); //convert JSON String to array or object
    return $data;
}

add_filter( 'rest_prepare_post', 'awh_filter_post_json', 10, 3 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.