Support » Developing with WordPress » How can I create a page for my plugin ?

  • Hello everyone,

    I am a bit new in wordpress development and don’t get everything, as simple as it can be. I am currently developing a plugin to browse and read files in an external ftp server. I used the ftp function from php, and it is so far working well.

    However, I am encountering a little problem, I wrote the most part of my plugin in class-myPluginName-public.php, and in this file I am using a tag to redirect to another page: download.php?file=file_name . In this page there will be a function called to download a file with a query var, and then the user will be redirected back to the index page of the plugin.

    BUT my problem is that I don’t know how to create this download.php page, as even if I create a page download.php in my plugin folder I need to write some code to make it a real page without having to create a new page in the admin panel.

    I hope I explained clearly, and that you can help me.

    Thanks in advance 🙂

    • This topic was modified 10 months, 1 week ago by  jlamy.
    • This topic was modified 10 months, 1 week ago by  jlamy.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You should start here.

    Moderator bcworkz


    I’m unsure of what you are trying to do. The best I can tell is you want this download.php file in your plugin folder to be a template for a WP page added to the site. Then when this WP page is requested, the code on download.php file executes. Am I close? I’ll assume so for now, please clarify if I’m off.

    Adding a WP page can be done on the plugin activation hook. Then the page is added only once. Since people deactivate/reactivate plugins for various reasons, your activation callback needs to check if the page exists before trying to add it.

    Page templates are the realm of themes, not plugins. There are work-arounds. Your activation script first adds the WP page based on the default template. Then the page’s template meta value (key “_wp_page_template”) is altered to point to your plugin file instead of the theme’s.



    Hello bcworkz, thanks for your answer.

    Yes you are close actually but I don’t want to trigger the code in my download.php page when the WP page is requested, but I want to trigger it by calling a function from my download.php page in my WP page.
    So basically I would like to have more than one page from my plugin to execute functions, like many plugins I have seen out there.
    Or do you have any resources to recommend me in order to understand better how a plugin is made (like with filters and actions too), because the official tutorials on are not really clear to me :/

    Moderator bcworkz


    OK then, my previous plugin template comments still apply. Whether that template calls a function from your plugin or if the code is on the template itself or elsewhere within the WP namespace makes little difference, yes you can do that.

    “official tutorials on” would be far from clear, because all resources are on! The .com versus .org distinction has caused much confusion. While there are many similarities, one resource cannot be applied to the other. Did you really go to or was that just something you auto-typed without thinking? (I’ve auto-typed “.com” myself several times)

    If you haven’t yet found the Plugin Handbook, that is the best resource I can recommend. Chapter 4 goes into action and filter hooks in detail. It doesn’t say anything about templates because templates are the realm of themes. As I previously mentioned, workarounds are possible. Once you have a better understanding of hooks, you may find there is not a need for a template, all may be able to be accomplished through hooks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I create a page for my plugin ?’ is closed to new replies.