Using Add Filter

This will be a simple snippet to show the usage of add_filter() in WordPress. I will show you how you a simple usage of this powerful WordPress hook!

function rda_hello_world_callback(){

	echo  apply_filters( 'rda_hello_text', "Hello world!" );

}

Then here's the snippet to modify our message in the shortcode.

function rda_hello_text_callback( $text ) {

	$text = $text . ' Good morning!';

	return $text;

}

add_filter( 'rda_hello_text', 'rda_hello_text_callback' );

Now if you're done with it, our output would be like this.

Hello world! Good morning!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.