0

A while back, I had someone here help me craft a custom mu-plugin (aka: "must use" plugin) that was designed to specially handle 404 server responses. Here is that thread for context, complete with the specific code I'm referencing:

Question about repurposing WordPress 404 handler

I'm just now revisiting this project and trying to resume development on it, but am running in to some issues with using the "get_template_part" method within the mu-plugin file .. trying to pull in specific PHP template files that are part of my child theme. It doesn't seem to be working, however, and I'm wondering if either it isn't possible, -- OR -- if there might be something obvious or essential that I'm missing.

I know that I'm able to reference methods such as get_header() and get_footer() without any issues in the mu-plugin file, so I don't think I need to load the entire WP core in order to be able to use get_template_part. I've also tried to use "include" and "require" instead of "get_template_part", and that didn't work either. This leads me to suspect that I might need to set some kind of "base path" or something, though I'm not entirely sure how I might go about that.

The reason I'm eager to get this all working, by the way, is because I've already done a significant amount of custom programming within my child theme, and all of the code that I'm trying to pull in and render to the browser using the mu-plugin currently lives within that child theme. Having to duplicate all of that code within my mu-plugin file certainly wouldn't be ideal, and would likely be more difficult to maintain moving forward. So .. hopefully I can find some kind of solution to this. Please advise.

2
  • If it doesn't work as you expected, what does it do instead? PHP error? WSOD? Loading a template that is incorrect? I see there is no code in your question, as this isn't a forum your question should contain everything needed to understand it Commented Jun 10, 2021 at 17:31
  • Well .. I've only recently learned that the get_template_part() method can NOT be used in plugin files .. at least not without helper libraries (one of which I've found on Gitub). However, I think I may need to abandon this route, as my recently successful attempts at using the include() method have proven that this is going to be far more complicated that I'd originally thought (I was failing to append the ".php" file extensions, which apparently isn't necessary with the get_template_part() method). Regardless, I'm open to suggestions if you think I've provided enough clarification. Commented Jun 15, 2021 at 16:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.