0

I'm trying my hands at developing a plugin but have run into an issue I can't seem to find any good answers to.

I want users to put a shortcode on any page they want, and the shortcode is replaced with custom content from my plugin. So far I've achieved this and replace the shortcode with a PHP file.

However, I have seen other plugins do the following, but I don't know how:

I would like all subsequent page requests to go to the same page, where the included PHP file handles which content is being displayed.

Say I add a page with the URL /mypage On this page I add the shortcode [mytag]. This code is, for example, replaced with a list of links. One link points to /mypage/one and another to /mypage/two

I don't want to create subpages called "one" and "two", but I want the included PHP file to do its custom stuff. Some stuff for "one" and other stuff for "two".

How can I create such rewrite rules so that they work no matter what page (or subpage) you put the shortcode on? How should the PHP file included in the shortcode handle these subpages (or sub-subpages)?

  • If your code is open source, could you give us a link? Are you saying you want 'one' and 'two' to be passed as GET parameters to a PHP script or Wordpress document, but the same PHP script/Word document each time? Do you know how to read the GET parameters in a WordPress plugin? – barrycarter Oct 31 '14 at 16:29
  • The code isn't online. I'm not picky on how the PHP script knows which page/post it is on, but as long as there is one page that includes the shortcode, the code behind that shortcode should (hopefully) also handle all requests to supages, like "one" and "two" in my example. – GTHvidsten Oct 31 '14 at 16:31
  • Is it private? If not, could you put it online on github or something? That would even allow people to help you by directly editing your code. – barrycarter Oct 31 '14 at 16:33
  • At the moment it's nothing more than a plugin that has registered a shortcode using add_shortcode, so not much to show, really. – GTHvidsten Oct 31 '14 at 16:36
  • So you haven't written the function that processes the shortcode? Something like "THIS_PAGE_URL/one" and so on? – barrycarter Oct 31 '14 at 16:45

Your Answer

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

Browse other questions tagged or ask your own question.