WordPress.org

Ready to get started?Download WordPress

Forums

How to add a new PHP file accessible via a friendly URL? (6 posts)

  1. michuk
    Member
    Posted 7 years ago #

    I'm writing a plugin which requires a special webpage. I would like it to be accessible via some friendly URL, like http://myblog/do-something/. How do I set it up?

    The way I'm doing it now is
    a) creating a category "do-something"
    b) creating a template file category-XXX.php (where XXX is the ID of the category I create)
    c) enter the HTML & PHP code that calls the plugin and does what it is supposed to do in this new file.

    I know it's a dirty hack and there must be a way to do it nicely, but I could not find any valuable hints how to do so in the online help pages about templates.

  2. I recently noticed this plugin: http://txfx.net/code/wordpress/page-links-to/ which allows a WP page to redirect to any other page. Might be what you're after.

  3. davidchait
    Member
    Posted 7 years ago #

    I've found my 'favorite' approach is to use a Page Template, as then the user can name the page anything they want -- and if there was other 'user content' to show, they could add it into the page content, and the plugin/page-template can do with it what they will.

    Otherwise sounds similar to your approach.

  4. michuk
    Member
    Posted 7 years ago #

    Yesm using a page template an "runphp" plugin works well, too. This is probably the best way to do it, though I still think it's a hack :)

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    The best way to do it is to use the WP-Rewrite stuff and create your own rewrite rule inside wordpress. This way you can take a specific name.

    Examine the UTW plugin. It uses this method to take the name "tag", so that blog.com/tag/whatever will get intercepted by UTW.

  6. michuk
    Member
    Posted 7 years ago #

    Thanks Otto for your hint. UTW is an interesting plugin and I may use it in other ways as well, actually.

    I'm marking this topic as "resolved" since I got what I wanted. Thanks again for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags