WordPress function add_filter not working [Solved]

Today I was trying to custom code the rel_canonical function of my wordpress blog but wasn’t able to override the function using add_filter function of wordpress.

WordPress function add_filter not working [Solved]This could either be that add_filter don’t work for functions inside wp_head() function? or for that matter they might not be able to override when a function to be overridden is called inside any other function?

Anyway, the solution to this was that instead of adding filter using add_filter function of wordpress, I simply removed the function and added my custom function for rel_canonical to show my customized canonical urls (as wordpress original canonicals were not perfect as per seo – yes google webmaster tools complains about it too)

Solution for WordPress function add_filter not working

Well the solution is to use remove_action for that function from the wp_head and add the custom function.

Use the following code to remove the action from the desired location in your functions.php

if( function_exists( 'function_we_want_removed' ) ){
 remove_action( 'wp_head', 'function_we_want_removed' );
}

Once removed, if you want to add any other function of yours in its place simply use:

add_action( 'wp_head', 'function_we_want_included' );

function function_we_want_removed{
  // functions code here
}

If you wanted to simply modify the function you can copy it’s data here and modify as you wanted it to be!

This way you can fix the wordpress function not being removed from wp_head while trying to override using add_filter hook.

 

hire best wordpress php css developer
Need Help? Hire me now!
I can help you in anything related to webdevelopment, including: HTML, CSS, PHP & MySql, WordPress (plugins & themes development, others), regular expressions, server management, etc.

Leave a Reply

Your email address will not be published.