how to use add_filter in wordpress

22:57

add_filter( string $tagcallable $function_to_addint $priority = 10,int $accepted_args = 1 )

Description

WordPress offers filter hooks to allow plugins to modify various types of internal data at runtime. A plugin can modify data by binding a callback to a filter hook.

function example_callback( $example ) {
    // Maybe modify $example in some way.
    return $example;
}
add_filter( 'example_filter', 'example_callback' );

Parameters


$tag

(string) (Required) The name of the filter to hook the $function_to_add callback to.

$function_to_add

(callable) (Required) The callback to be run when the filter is applied.

$priority

(int) (Optional) Used to specify the order in which the functions associated with a particular action are executed. 

Default value: 10

$accepted_args

(int) (Optional) The number of arguments the function accepts.

Default value: 1


add_filter('the_title','modified_content');

function modified_content($title)
{
   return '<h2>'.$title.'</h2>';
}
 

No comments:

Powered by Blogger.