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

Disable Automatic Login After Registration

When we enable customer registration on My Account page, We will know that when new user is register it’s automatically logged in .
it need to change when we need to manually approve each user.

Elementor shortcodes

Elementor is a popular page builder plugin for WordPress that allows you to create and customize web pages using a drag-and-drop interface. Elementor provides a wide range of built-in widgets and elements, and you can also create your own custom elements using shortcodes.

Disable Repeat Purchase Of Product

To disable repeat purchase of products in WooCommerce, you can implement a custom solution using a combination of code snippets and WooCommerce hooks. The idea is to prevent customers from adding the same product to the cart if it already exists in the cart. Below are the steps to achieve this: