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( 'rest_prepare_post','androapp_overwrite_content_pre', 8, 3 );

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

To Add after the post content

Add this code to functions.php

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

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

To Replace some html text

Add this code to functions.php

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

function androapp_overwrite_content($data, $post, $context) {
  $inner_data = $data->data;
		if(!($inner_data['type'] == "post" || $inner_data['type'] == "page")){
			return $data;
		}
		$postContent = $inner_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);
		$inner_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( 'rest_prepare_post','androapp_overwrite_content', 11, 3 );

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

		return $data;
}

Related Post

Leave a Reply

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