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

  • |

    Gloss WordPress Plugin

    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!Today, I officially released my first public WordPress plugin, Gloss. Gloss is a dictionary/glossary management plugin I decided to build which…

  • |

    Add IE Conditionals to wp_enqueue_style

    When creating a WordPress theme, it’s best practice to use wp_enqueue_style for adding all stylesheets, including style.css. At first glance, this can pose a challenge if you want to conditionally include CSS based on the browser (like IE-only styles, for example). Luckily, there is a quick way to do this in WordPress using $wp-styles: global…

  • | |

    Recap: Year Two of Self Employment

    As I sit here writing this, I can’t believe I’ve completed 2 full years of self employment. I think another shocking revelation is I’m actually doing pretty well. This has been a strong growth year for me, and I’ve got a lot more clarity in what I’m doing, and what I need to do.

  • |

    A Year of Responsive Design with WordPress

    A little over a year ago, my second book (and the first one to actually be in book stores) came out. It’s called Responsive Design with WordPress and it’s all about how to leverage WordPress to create responsive themes. It’s been an incredible year and I wanted to talk about two things: what has happened since the book’s release,…

  • |

    Join Me for the 1st NEPA Hackathon!

    I’m happy to announce that I (with @nepawp) am working with @tecbridge1, and The University of Scranton ACM group to put on the first (of hopefully many) NEPA Hackathon! It will be held on May 11th, 2014 from 10am – 3pm at the Scranton Enterprise Center, at 201 Lackawanna Ave. Scranton, PA 18503.

  • Speaking at WordCamp Philly

    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!Just a quick note that I’ll be speaking tomorrow (Oct 20th) at WordCamp Philly! My talk is called Building a Simple…

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.