Custom Wordpress Template
While working on my website, I came across the requirement to showcase one of my pages, with different content, conditional to if user is logged in or not, that is when I was recommended Page Templates.
I am absolutely new to wordpress development, and hence seeking guidance and suggestions to achieve the following:
I have a page which needs to show content conditionally i.e:
1. That is when a user is not logged into the site, show – Login button section
2. When user is logged in the site, show – User already logged in.
how do I create a configure this page template to the original page?
What plugin are you using to achieve this functionality?
Is it WP Page Templates? If so, I recommend asking at https://wordpress.org/support/plugin/custom-page-templates-by-vegacorp/ so the plugin’s developers and support community can help you with this.
Oh, my bad. The capitalization of Page Templates made me think it’s about a plugin.
What you described is possible. Let’s take it step by step.
- Create a file, let’s say it’s named
my-custom-page.phpin your theme directory
- In that page header you’ll have to start with
- The rest of the page content, I suggest you copy paste from
page.phpof your theme, so it looks the same as the original page
- Then, you will want to modify that with something like
- The last step is to go in the Page editor and select the My custom page template.
wp_loginout();already checks if the user is logged in (is_user_logged_in) and if NOT, it shows a login button, if YES, it shows a log out button, but since you want more, I made the above code a bit redundant, but letting you modify as you want. Maybe you will want to get rid of wp_loginout() and show your custom button.
Here’s some links on the things described above:
- https://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/ (tutorial)
- https://www.ostraining.com/blog/wordpress/custom-page-template-wordpress/ (alternative tutorial)
Hope this helps,
- This reply was modified 1 month, 1 week ago by . Reason: typo
PS: Don’t edit the theme files directly, otherwise your changes will be overwritten whenever the theme is updated. Instead, create a child theme. and put your
my-custom-page.phpfile in the child theme folder.
Your login page is not the standard login page (
wp-login.php) so the
wp_loginout();function will not be helpful in your case, as it will direct users to wp-login.php not to your
How do i add the conditional code to this one and configure the same in page attributes? Is it possible?
Create a php file template, then change the template for your existing page.
I see you are using Elementor to build your website. That can make things easier, as the customization goes visual, not in code so I recommend asking at https://wordpress.org/support/plugin/elementor/ so the plugin’s developers and support community can help you with this. They might tell you more about an easier way to achieve this.
Let’s try to clarify some things
1. WordPress core has Page Templates described here: https://developer.wordpress.org/themes/template-files-section/page-template-files/ (this is what I meant above)
2. Elementor and other builder plugins have visualy created Templates you can create in Dashboard.
Visually created templates are awesome if you find all the features you want. If not, you’ll have to code part of your theme ( page templates – php files ) to do what you want – that requires some coding knowledge.
Hope things are a more clear now. I get that having the same name can be confusing.
- Create a file, let’s say it’s named
Create Page Template Wordpress
An Introduction to WordPress Page Templates The WordPress Template Hierarchy determines how your site is displayed to the world. Themes are one of WordPress’ most versatile features. By installing one on your site, you can radically alter its appearance to suit your needs. Template – Some WordPress themes have custom page templates, so the next Template section allows you to apply a template to your new page. The Order box allows you to order your page numerically. Pages are usually ordered alphabetically, but you can choose your own order by entering a number in this field. Save Draft or Preview Your Page. To add a WordPress page template to a page, edit or add a new page from the Pages menu located in the WordPress Dashboard. Find the Page Attributes section. In this section, you’ll see a drop-down list for available page templates. Create A Page Template; Add Function to Load the Template; Hope it is going to be a short but useful tutorial for you. Creating a Page Template for My Account. Well, the template was created for the purpose of making a My Account page for members. In this template just added some dummy HTML. You will have to change based on your needs.