I have created a custom page that I have called mypage.php.

It is in my template folder with al the other pages (index.php, page.php, …)

I want this page to be opened when i click on the below code.

<a href="https://wordpress.stackexchange.com/questions/257384/<?php site_url(); ?>/mypage.php">Go to page</a>

When I click on the link the url in my browser look like: http://localhost:8888/mypage.php which I guess is correct.

BUT it uses index.php as template ignoring the code I have into mypage.php

So all i am getting at the moment is an empty page with only my header and footer.

Is it possible to use pages in this way with WordPress? I had a look online and on this site but I haven’t been able to find a solution for this problem.

3 Answers
3

WordPress doesn’t load templates that way.

First: give the template a name:

To load a page template, first you’ll have to make sure your template has a name. To do that, you’ll have to have the following CODE in your template file (here mypage.php):

<?php
/**
 * Template Name: My Page
 */

Once you have the above PHP comment, WordPress will recognise it as a template file.

Then, assign the template to a page:

Now you’ll have to create a WordPress page (from wp-admin).

While you create the page, WordPress will give you the option to choose a custom template (if there is one). After you choose the template and Publish, that page will use your mypage.php file as a template.

Add Page Template

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *