Wordpress - add_filter passing function vars
I have a premade function which looks like so:
function truncate($string='', $limit='150', $break=" ", $pad="...") {
I need to pass the $limit
argument, but can't figure out how.
add_filter()
as well, as follows:
add_filter('the_content','truncate');
I want to pas开发者_如何学Pythons 20
as the $limit
.
For the life of me, I can't figure how.
Any help?
Cheers,
I'm not sure if there's something for this within Wordpress, but the easy option is to create a new function:
function content_truncate($string) { return truncate($string, 20); }
add_filter('the_content', 'content_truncate');
If you're using PHP >= 5.3 you might be able to use an anonymous function to make it a bit neater:
add_filter('the_content', function($string) { return truncate($string, 20); });
精彩评论