Let's say I have an function like:
function cc_get_content_preview() {
return apply_filters( 'cc_get_content_preview', get_the_excerpt(), 55 );
}
Here get_the_excerpt()
is the $value
that I can edit in an add_filter
correct?
Question: As you can see the second parameter, in apply_filters
(get_the_excerpt()
), is not a variable. Is it correct that I can call this parameter through a $variable name to my liking in the add_filter
function? Such as below ($cctoreturn)
:
//Set custom content preview for Aff posts
function cc_custom_content_preview($cctoreturn){
$post_id = get_the_ID();
if (is_sticky($post_id)) :
$cctoreturn = $post_id;
endif;
return $cctoreturn;
}
add_filter( 'cc_get_content_preview', 'cc_custom_content_preview', 20, 1);
Let's say I have an function like:
function cc_get_content_preview() {
return apply_filters( 'cc_get_content_preview', get_the_excerpt(), 55 );
}
Here get_the_excerpt()
is the $value
that I can edit in an add_filter
correct?
Question: As you can see the second parameter, in apply_filters
(get_the_excerpt()
), is not a variable. Is it correct that I can call this parameter through a $variable name to my liking in the add_filter
function? Such as below ($cctoreturn)
:
//Set custom content preview for Aff posts
function cc_custom_content_preview($cctoreturn){
$post_id = get_the_ID();
if (is_sticky($post_id)) :
$cctoreturn = $post_id;
endif;
return $cctoreturn;
}
add_filter( 'cc_get_content_preview', 'cc_custom_content_preview', 20, 1);
Share
Improve this question
edited Nov 8, 2018 at 11:51
RobbTe
asked Nov 8, 2018 at 11:35
RobbTeRobbTe
2622 silver badges16 bronze badges
1 Answer
Reset to default 2I can't really make sense of what you're trying to do. This code:
apply_filters( 'cc_get_content_preview', get_the_excerpt(), 55 );
Will let developers hook into the cc_get_content_preview
hook to change the value that the cc_get_content_preview()
function returns. When developers hook into an action or filter, they do so using a callback function. This function will receive any additional arguments passed to apply_filters()
as parameters on the callback function.
In you specific function, that would look like this:
function my_callback_function( $a, $b ) {
echo $a; // This will be the value of get_the_excerpt().
echo $b; // This will be the number 55.
}
add_filter( 'cc_get_content_preview', 'my_callback_function', 10, 2 );
But it looks like you're trying to do something like JavaScript and pass the full function through? That's not going to work. You can't put functions into variables and execute them later like you can in JavaScript.