Pawan Kumawat

How To Customize/Replace WordPress Post Excerpts

Example: Sometime we need to show content on frontend with adding some prefix or suffix or may be you have enter spelling mistakes in 2000 posts. so it is very difficult to modify 2000 posts so we can modify using filter . SO mistake will be replaced by correction.

 

For Modifying post content only:

 

function link_words( $text ) {
   $replace = 'Replace with';
   $text = str_replace( 'Want To replace text', $replace, $text );
   return $text;
}
add_filter( 'the_content', 'link_words' );

 

For Modifying post excerpt only

 

function link_words( $text ) {
   $replace = 'Replace with';
   $text = str_replace( 'Want To replace text', $replace, $text );
   return $text;
}
add_filter( 'the_excerpt', 'link_words' );

 

For Modifying post content and excerpt both

 

function link_words( $text ) {
   $replace = 'Replace with';
   $text = str_replace( 'Want To replace text', $replace, $text );
   return $text;
}
add_filter( 'the_content', 'link_words' );
add_filter( 'the_excerpt', 'link_words' );

 

Categories

Related Blogs

Upload Any File in My Account Registration Form

To allow users to upload a file in the My Account registration form in WooCommerce, you’ll need to customize the registration form and add a file upload field. We’ll use a custom function and a hook to achieve this. Here’s a step-by-step guide:

How to add custom style and script in wordpress

`wp_enqueue_scripts` is a crucial action hook in WordPress that allows you to enqueue or register scripts and stylesheets properly. It is commonly used by theme and plugin developers to load necessary CSS and JavaScript files onto the front-end of a WordPress website.

Convert PHP Array into JavaScript Array.

To convert both a normal PHP array, a multidimensional PHP array, and a nested PHP array into JavaScript arrays, you can use JSON encoding and decoding as previously explained. JSON is well-suited for handling various data structures, including both simple arrays and complex nested arrays.