Home    Articles

 

[WORDPRESS] Fatal error: Call to a member function add_rewrite_tag() on null

 

Fatal error: Call to a member function add_rewrite_tag() on null in /.../.../.../wp-includes/rewrite.php on line 172

There is a reason for this error, you may encounter this error when you install a new plugin or you have developed a new plugin.

This error should tell you that you have called a function before you should. Wordpress has a order in doing things. Becouse of this, global variable $wp_rewrite isn't available as object at the moment when you're are trying to use it.

The solution is to use a hook like add_filter('woocommerce_init','function_to_call'); to make sure WP is loaded and all global variables are available to be used. As example, in this case you will call your function after Woocommerce has been initialized.

...in my case, the error appeared when i've tried to register a new taxonomy right on plugin init in a new developed plugin.

 

That's all.

by