Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodica-andronache/42b57f63006466678200feb84f72a82e to your computer and use it in GitHub Desktop.
Save rodica-andronache/42b57f63006466678200feb84f72a82e to your computer and use it in GitHub Desktop.
How to use filters with parameters
In the parent theme
--------------------
Apply the same filter in multiple places, but with different parameters:
apply_filters ( 'xxx_filter_name', 'value_to_be_filtered_1', 'parameter_1a', 'parameter_2a' )
apply_filters ( 'xxx_filter_name', 'value_to_be_filtered_2', 'parameter_1b', 'parameter_2b' )
In the child theme
------------------
add_action( 'after_setup_theme','child_theme_setup_function' );
child_theme_setup_function() {
/* Add filter */
add_filter( 'xxx_filter_name','child_theme_filter_function', 10, 3 ); /* 10 - priority, 3 - number of parameters ( value to be filtered plus the parameters ) */
}
function child_theme_filter_function( $arg1, $arg2, $arg3 ) {
/* filter the content based on the arguments */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment