Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress-添加过滤器传递函数变量_Php_Wordpress - Fatal编程技术网

Php Wordpress-添加过滤器传递函数变量

Php Wordpress-添加过滤器传递函数变量,php,wordpress,Php,Wordpress,我有一个预制函数,看起来是这样的: function truncate($string='', $limit='150', $break=" ", $pad="...") { 我需要传递$limit参数,但不知道如何传递。 我也在调用add_filter(),如下所示: add_filter('the_content','truncate'); 我想通过20作为$limit 就我而言,我不知道该怎么做 有什么帮助吗 干杯,我不确定Wordpress中是否有这样的功能,但简单的选择是创建一个新

我有一个预制函数,看起来是这样的:

function truncate($string='', $limit='150', $break=" ", $pad="...") {
我需要传递
$limit
参数,但不知道如何传递。
我也在调用
add_filter()
,如下所示:

add_filter('the_content','truncate');
我想通过
20
作为
$limit

就我而言,我不知道该怎么做

有什么帮助吗


干杯,

我不确定Wordpress中是否有这样的功能,但简单的选择是创建一个新功能:

function content_truncate($string) { return truncate($string, 20); }
add_filter('the_content', 'content_truncate');
如果您使用的是PHP>=5.3,则可以使用匿名函数使其更加整洁:

add_filter('the_content', function($string) { return truncate($string, 20); });
可能重复的