Fixing the Fatal ‘add_rewrite_tag()’ Error

I’m working on a WordPress little side project where I am registering a new Custom Post Type and Taxonomy and came across this:

 Fatal error: Call to a member function add_rewrite_tag() on a non-object...

After doing a Google Search to try to figure out what the issue is, all I came up with was “disable all of your plugins and reenable them to see which is the bad one.” That doesn’t help me because I know the one I’m developing is the bad one. My next step was just do to a Find for the term ‘rewrite’ and wouldn’t you know it, I came up with the the solution.

As it turns out, I was trying to register the taxonomy for my CPT before actually registering the CPT. If you ever run into the error yourself, try moving ” register_taxonomy” onto the line directly under the link that has “register_post_type.” My code was below it, but due to certain hooks I called, register_taxonomy was getting called first.

You might also want to prefix your taxonomies and CPTs; conflicts can arise that may also lead to that error. Happy Coding!

Similar Posts

  • Good Books for Web Development

    I’m teaching a couple of web development classes this semester and have been receiving a lot of questions as to what books would serve as good resources. Here’s a short list, starting with the ones I’ve chosen for my classes. HTML and CSS: Design and Build Websites: This is possibly the best book I’ve used for…

  • Answer Questions that are Being Asked

    Perhaps you’ve heard of the Socratic Method? At The University of Scranton, we loved good old Socrates, so we studied him and his methods a lot. The general idea, derived from how he would debate people, is to ask a series of questions until you get to the truth of the matter. He would often…

  • |

    Is Gutenberg a Page Builder?

    There’s been lots of discussion around whether the WordPress community should use Gutenberg when tools like page builders exist. This begs the question, “Is Gutenberg even a page builder?” In this video, I answer that question.

  • |

    Why the WordPress.com / Spotify Deal is Bad for Podcasting

    Imagine telling Gordon Ramsay that he cooked dinner last night…why not just serve the leftovers to his customers today? While I’m no Michelin chef, I do create a lot of content. And you can’t just throw the left overs out there and expect the same quality content. So why are WordPress.com and Spotify telling us to do that?

  • |

    Testing your Responsive Site

    Over the last year or so I’ve been involved with a few major projects that required responsive design/development. One of the most important things to remember about a responsive design is that it’s not just good enough to make sure your design shrinks with a smaller browser on your computer. Presumably, you’re doing this because…

  • |

    Scrubs Quotes App

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! I don’t do too many things on a whim, but the other night when I saw a group dedicated to…

One Comment

  1. I also kept finding the same “Disable plugins” lol, not much help when you’re the dev. Much appreciated!

Comments are closed.