0

New to WP development. I want my plugin to dynamically show content for certain urls, for example, when the user navigates to /my-plugin or /my-plugin/key, my plugin would provide the content. The Events Calendar appears to do this. I don't want the user to have to create pages and add shortcodes. I've been looking through the filters but haven't found anything. the_content filter isn't quite what I want, as it looks like that only changes the content for already existing posts/pages.

Is there a hook/filter that can do this? Or should it be done some other way?

  • You could create a rewrite rule for this after you create a dynamic page with wp_insert_post. Look at the docs there's note below hope it helps – Samuel Elh Jun 4 '16 at 21:27
0

@SamuelEth is right, creating a page to handle this (with rewrites) could be the way to go.

Another alternative would be registering a custom post type of my-plugin(with the admin UI setting off since you don't want user access to it)...

...and dynamically detecting and handling calls to that, the advantage being the rewrite is done for you somewhat. Because of that you can probably hook in to check the query is of your custom post type, and if so modify the query and/or output to point to generate content you want.

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.