This page redirects to an external site: https://developer.wordpress.org/reference/functions/add_filter/
Languages: English • Italiano • 日本語 Русский • (Add your language)
Hook a function to a specific filter action.
<?php add_filter( $tag, $function_to_add, $priority, $accepted_args ); ?>
The function returns true if the attempted function hook succeeds or false if not. There is no test that the function exists nor whether the $function_to_add is even a string. It is up to you to take care. This is done for optimization purposes, so everything is as quick as possible.
The filter img_caption_shortcode is applied in media.php using the following call:
// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
return $output;
The target filter function will be called with three arguments:
In order for the filter function to actually receive the full argument list, the call to add_filter() must be modified to specify there are 3 arguments on the parameter list.
add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3);
/**
* Filter to replace the [caption] shortcode text with HTML5 compliant code
*
* @return text HTML content describing embedded figure
**/
function my_img_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $val;
$capid = '';
if ( $id ) {
$id = esc_attr($id);
$capid = 'id="figcaption_'. $id . '" ';
$id = 'id="' . $id . '" aria-labelledby="figcaption_' . $id . '" ';
}
return '<figure ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: '
. (10 + (int) $width) . 'px">' . do_shortcode( $content ) . '<figcaption ' . $capid
. 'class="wp-caption-text">' . $caption . '</figcaption></figure>';
}
add_filter( 'media_upload_newtab', array( 'My_Class', 'media_upload_callback' ) );
add_filter( 'media_upload_newtab', array( $this, 'media_upload_callback' ) );
add_filter( 'the_title', function( $title ) { return '<b>' . $title . '</b>'; } );add_filter() is located in wp-includes/plugin.php.