• farhadk100

    (@farhadk100)


    Hi.
    So, I’ll get straight to this.
    I have a wordpress website with a custom theme and everything. Now I need to load a custom PHP file like mywebsite.com/myfile in it.
    now here is the issue:
    I’m using %postname% format for my posts. I’ve been using it for more than a year, and using this, when I wanna load myfile, it returns a 404 error. But if I use default permalink option, it loads myfile perfectly.
    So my question is, how can I have %postname% permalink format and still be able to load my non-wordpress files?
    Thank u in advance for your answers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    My trick: Put all of your PHP in a shortcode and then drop that shortcode into an otherwise empty page.

    Moderator bcworkz

    (@bcworkz)

    Steve’s “trick” is completely valid, but for the sake of presenting alternatives, you could make your code page into a page template file. This mainly means adding a comment to the very top right after the initial <?php that looks roughly like this: /* Template Name: My Template */ Place the template file in the folder of your active theme, preferably a child theme.

    You may want to add calls to get_header() and get_footer(). If you do not, you should at least call wp_head().

    Add a new page based on your custom template. Give it a title in order to generate a permalink. Publish the page.

    If you do go the shortcode route, remember all content must be returned from the shortcode handler, do not echo out anything. If your current code as a lot of echo and/or HTML content, use the output buffer to collect all output into a variable which can then be returned.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘loading a custom PHP file’ is closed to new replies.