Skip to content

Instantly share code, notes, and snippets.

@cobaltapps
Created September 13, 2017 18:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cobaltapps/18e8530a4d385e203c89168842322f5a to your computer and use it in GitHub Desktop.
Save cobaltapps/18e8530a4d385e203c89168842322f5a to your computer and use it in GitHub Desktop.
A simple example of how to filter a custom value into an applied filter.
/*
* This is the cleanest way to do this, using an anonymous function,
* but such a function requires PHP 5.3 or higher.
*/
add_filter( 'theme_read_more_text', function() { return 'Read more ->'; } );
/*
* This is the same anonymous function example,
* but formatted differently for those who might
* the first example a bit confusing.
*/
add_filter( 'theme_read_more_text', function() {
return 'Read more ->';
} );
/*
* This example is the more "traditional approach
* using a named function for pre-5.3 PHP compatibility.
*/
add_filter( 'theme_read_more_text', 'my_custom_read_more_text' );
function my_custom_read_more_text() {
return 'Read more ->';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment