0

I have a plugin that I'm working on and I'd like the plugin to create and display custom content on a "page" created using a rewrite rule.

I've successfully created the rewrite rule with add_rewrite_rule() and when navigating to that URL, I don't receive the "Page not found" error.

What I'm having trouble figuring out is how to have the plugin display content when that URL is accessed. I know how to do this in a theme with get_template_part( 'content', $page_template ); but how can I have the plugin serve this functionality? The plugin can't add a file to the Theme, so how can I have custom page content (via the plugin) show up? Instead of using a theme's page.php, I'd like the plugin to pull from my-plugin/views/custom.php

I've seen other plugins that do this sort of thing, but haven't been able to track down how it gets the content to the public user.

I'm sure I'm overlooking something fairly simple, but I'm having a hard time tracking down the issue, I'm not even sure exactly how to search for what I'm looking for.

Any help would be greatly appreciated.

Thanks.

0

After more digging, I finally stumbled across what I was looking for. Using the template_include filter is working for me.

Plugin Templating within WordPress

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.