Removing tooltips
-
Hi,
I found the below code to remove tooltips from navigation menu in Twenty ten theme
function remove_title($input) { return preg_replace_callback('#\stitle=["|\'].*["|\']#', create_function( '$matches', 'return "";' ), $input ); } add_filter('wp_list_pages','remove_title');
It works but can anyone please go through the code and explain what each line does. I want to learn about how all the functions work.
Thanks!
-
line 1: the function keyword identifying this as a declaration followed by the function name and in this case one parameter.
line 2: the keyword return means ‘send the following back to whatever called the function’. In this case what is going to be returned is the output from a function called
preg_replace_callback()
. This is a PHP function. You can look it up for the details but basically it lets you search and replace a string using a pattern matching syntax called regular expressions– Perl compatible regular expressions in this case. Regular expressions are a mind bending language in there own right so you will need to spend some time understanding that.line 3:
preg_replace_callback()
lets the author of the code provide a function to process the match. You can use built in functions likestrtolower()
or write your own just likeremove_title
or, as in this case, use a kind of disposable one time nameless function.create_function()
is a PHP builtin that lets you write this anonymous function. So, if you look atpreg_replace_callback()
you have three parameters separated by commas– the pattern to match, the callback and the input value.The last line adds the remove_title function to the WordPress filter hook named ‘wp_list_pages’.
There ya go.
Thanks. I need to understand why that particular regular expression pattern is used here.
- The topic ‘Removing tooltips’ is closed to new replies.