How create template page in custom theme & register it via theme's functions file + permali

Can I create a .php page in my custom theme without using the admin dashboard to assign a page to the template first and if so, how do I register the page in functions.php and create a slug or permalink for it so a request for /pagename will utilize the new page? Thanks!

  • Tyler Postle
    • CGO

    Hey Michelle,

    Hope you're doing well today and thanks for your question!

    I'm not 100% sure what you're trying to do here. Are you wanting to make a custom post type or just one custom page? What are you wanting to put on this page?

    By default single posts use a single.php file; however, if you have a custom post type then you can make a copy of that and call it single-posttypename.php and those posts will use that file instead.

    I may be misunderstanding your plan. Look forward to hearing back then I can take another look :slight_smile:

    All the best,
    Tyler

  • Michelle
    • WPMU DEV Initiate

    I'm trying to create custom pages without having to use the dashboard. For example, an about page. I named the template page-about.php but I get a page not found, I think because I haven't registered the page with WP. Any way I can create my template pages that contain content including the standard functions for initializing wordpress, header, footer and then register them with WP in my theme's functions.php and without having to use the dashboard? Thanks!

  • Tyler Postle
    • CGO

    Hey Michelle,

    Hope you're doing well today and apologies for the delay.

    If you want to make a custom template for the page then the page has to exist within WordPress first. Example, create a page in WordPress called About and make sure that the slug is also "about" - then you can create your custom template page-about.php and since "about" matches the slug of that page - it will use that template when displaying it.

    I'm wondering why you want to make custom pages without using the dashboard? Is there a specific functionality you are after? Perhaps that will help us provide more efficient support for you :slight_smile:

    By the sounds of it my suggestion above will be your best bet. All you have to do is create it in the pages, you don't have to add content or anything else if you want don't want too. Long as the page exists and matches the slug in the name of your template page that it will use that template and display whatever you tell it too.

    Hope that helps! Let me know if you still have further questions.

    Cheers,
    Tyler

  • Tyler Postle
    • CGO

    Hey Michelle,

    Hope you're doing well today!

    I just wanted to follow up on this and mention that perhaps virtual pages might be more what you were looking for?

    This post will give some good information on that: http://wordpress.stackexchange.com/questions/9870/how-do-you-create-a-virtual-page-in-wordpress

    Same with this one here: http://stackoverflow.com/questions/17960649/wordpress-plugin-generating-virtual-pages-and-using-theme-template

    That sounds like it might be more what you were after :slight_smile:

    Let us know if you have any further questions!

    Cheers,
    Tyler

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.