Created
May 12, 2017 14:00
-
-
Save rodica-andronache/42b57f63006466678200feb84f72a82e to your computer and use it in GitHub Desktop.
How to use filters with parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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