AndroApp Tricks to change post content

This guide is for little advanced users, who know little bit of php.

We will suggest to try out below changes on test setup and check it is not breaking your website or app.
It will change only the app content, your website content remains as it is.

To Add before the content of all posts

Add this code to functions.php

add_filter( 'json_prepare_post','androapp_overwrite_content_pre', 8, 3 );

function androapp_overwrite_content_pre($data, $post, $context) {
 if(!($data['type'] == "post" || $data['type'] == "page")){
 return $data;
 }
 $textToBeAdded = "add your html code here";
 $data['pwapp_post_content'] = $textToBeAdded.$data['pwapp_post_content'];
 return $data;
}

To Add after the post content

Add this code to functions.php

add_filter( 'json_prepare_post','androapp_overwrite_content_post', 9, 3 );

function androapp_overwrite_content_post($data, $post, $context) {
 if(!($data['type'] == "post" || $data['type'] == "page")){
 return $data;
 }
 $textToBeAdded = "add your html code here";
 $data['pwapp_after_post_content'] = $textToBeAdded;
 return $data;
}

To Replace some html text

Add this code to functions.php

add_filter( 'json_prepare_post','androapp_overwrite_content', 11, 3 );

function androapp_overwrite_content($data, $post, $context) {
		if(!($data['type'] == "post" || $data['type'] == "page")){
			return $data;
		}
		$postContent = $data['pwapp_post_content'];
		$toBeReplacedText = 'paste your text to be replaced here';
		$replaceWithText = 'text you want instead, you can leave it empty as well';
		$postContent = str_replace($toBeReplacedText, $replaceWithText, $postContent);
		$data['pwapp_post_content'] = $postContent;
		return $data;
}

To Make the changes only for selected posts

Lets say you want to change the image dimension for some specific post, like for post id 444
Add this code to functions.php

add_filter( 'json_prepare_post','androapp_overwrite_content', 11, 3 );

function androapp_overwrite_content($data, $post, $context) {
		if(!($data['type'] == "post" || $data['type'] == "page")){
			return $data;
		}
                if($post['ID'] == 444){
                      $data['pwapp_feed_image_dimension_type'] = 'full';
                      //you can change it to full, preview or noimage
                }

		return $data;
}

similarly you can set post_content to preprocessed, postprocessed OR loadurl to change the post content type.
ie.

add_filter( 'json_prepare_post','androapp_overwrite_content', 11, 3 );

function androapp_overwrite_content($data, $post, $context) {
		if(!($data['type'] == "post" || $data['type'] == "page")){
			return $data;
		}
                if($post['ID'] == 2522){
        	     $data['pwapp_post_content_type'] = 'loadurl';
		}

		return $data;
}

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *