Wordpress Custom Template page not displaying - wordpress

Unable to get my custom created page in page attributes Templates, rest all the pages are still shown in the dropdown but new created page is not listed. I have created a custom page in PHP and uploaded it in wp-content->themes->my-theme in the root directory.
Kindly assist, Thanks

Add at the beginning of your custom page:
<?php
/*
Template Name: Template name
*/
?>
The second template name will the name of your template

Make sure that your template file name is like page_{template-name} and not page-{template-name}.
Also add this at the beginning of the template.
<?php /* Template Name: Example Template */ ?>
Check this out for more details https://developer.wordpress.org/themes/template-files-section/page-template-files/

Related

how to move the physical location of the permalink header in wordpress?

Does anyone know how to move the physical location of a permalink header in wordpress? I dont want it to be the first thing that is seen but rather I want a shortcode item there.
In your page.php you can delete the php function for calling the header ( the_header() ) and put the function to call the shortcode ( do_shortcode() ).
This way the page is not embeding the header.php but get the code of your shortcode at this place of your markup.
Page Template:
You can create a page template in your theme-folder. For this, you can simple duplicate the page.php and call it page-yourname.php. At the top of your page you add the name of the page template:
<?php /* Template Name: Example Template */ ?>
In that file you do the adjustments that you like to do with the shortcode.
https://developer.wordpress.org/themes/template-files-section/page-template-files/
With the template structure of wordpress, the template will automatically be found at the edit screen of your pages. It will be found on the right side under "page attributes".
You can set the template for your individual pages. So your adjustments to the template will only affect your pages, where you selected the template in the page attributes.

Custom page template displays the archive template

I have a custom page template named "page-news.php" and it contains
<?php
/*
* Template Name: News
*/
get_header();
?>
test
<?php
wp_footer();
get_footer();
?>
and I then create a page and set the template to "News" but when I view the page, it does not display the contents on the page-news.php custom page template, instead it display the archive.php contents (I have test it, whatever I put unto the archive.php contents, it display on the page that I hook unto the page-news.php custom page template). Any ideas, help please? I'm running WP 4.7.2.
Please rename the file name i.e. from 'page-news.php' to 'news.php' or any other name but don't add 'page-' in the file name & then select the template again for the page in the admin backend.
Hope, this will help you.

Wordpress custom folder as homepage

In my wordpress I have a folder name custom which is a custom script. I visit myexample.com/custom the script does work. But I wish to use myexample.com for the script instead of myexample.com/custom. I want to replace the custom script rather than displaying the default homepage of wordpress.
Just add template comments in top of you main file under the custom folder.
<?php /* Template Name: Example Template */ ?>
How to create page template: http://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/
Create a new page select this page template from page template dropdown and set this page as home page.

Custom 404 Wordpress with custom fields

I'm running into the following problem. I have a 404.php but I need to use some custom fields on that page. So I preferably need to make a page and use that. But I can't seem to override the default behaviour.
Is there any way to fix this?
Try this one:
Remove all the code from the 404.php
put a single line code of your custom template:
<?php get_template_part( 'new-template-name' ); //don't put extension(.php) ?>
Here you have to create a new template with the same above mention name
Thanks.
Here is how I managed to accomplish it:
Create an empty page template in theme directory named 404-content.php with the following lines of code:
<?php
/* Template Name: 404 Content */
Create ACF field group with the desired custom fields for the 404 page (ex. title & contents). The group's post template should be set to "404 Content".
Create a 404 page in WP admin. Select the 404 Content as its template, and fill the custom fields with the desired content. Note the post-id of the page created.
Update 404.php in your theme directory to display your custom fields. For example (replace xxxx with the post-id of your 404 page):
echo get_field('404-page-title', xxxx);
...
echo get_field('404-page-content', xxxx...)
Hope that helps someone :)

Exclude templates in wordpress page

If I put a file up in my theme folder named foo.php that only contains <h1>Foo</h2>, WordPress will automatically pull in the home.php file.
Is there any function to prevent that and have it simply render the file foo.php. I'll still want to be able to use the wordpress functions from that page.
Thanks!
<?php
/*
Template Name: Foo
*/
?>
<h2>Foo</h2>
Saved (obviously) as 'foo.php'.
Then, when you publish a page, through the dashboard using the 'Foo' template, that template will be used.

Resources