Ready to get started?Download WordPress


Template file accessible with vanity URL (6 posts)

  1. onepixelsolid
    Posted 1 year ago #

    How do you make a template file accessible via a vanity URL 'without' assigning it to a page in the WP admin?

    For example say I have a file blah.php, can I programmatically make that file accessible via http://www.mywebsite.com/blah/

    Can this be done via functions.php?

  2. keesiemeijer
    Posted 1 year ago #

    You could create a directory /blah and put an index.php file in there. Then you can link to http://www.mywebsite.com/blah/

  3. mathis@Tambour
    Posted 1 year ago #

    I think you can do like that with templates.
    Add this at the begin of your page-blah.php
    Template Name: Blah
    And you have a new attribute on the right of your edit page !

  4. onepixelsolid
    Posted 1 year ago #

    mathis@Tambour the solution I wanted was to do it without the Admin interface (new/edit page)

    keesiemeijer that could work...

    I ended up not needing it, however for future it would be good to be able to do such a thing via a declaration in functions.php or similar.

  5. keesiemeijer
    Posted 1 year ago #

    You can do it with this in your theme's functions.php with a template called blah.php in your current theme folder: http://pastebin.com/uDg7NbAk

    It adds the rewrite rule and query var for /blah and uses the template file blah.php if you are visiting http://www.mywebsite.com/blah/

    Be aware that if you publish a page or post with slug 'blah' the template blah.php will be used.

  6. onepixelsolid
    Posted 1 year ago #

    Nice, will check that out.

Topic Closed

This topic has been closed to new replies.

About this Topic