I wonder if I can have two single.php templates for different sources.
The problem is:
- I have the full website, with the blog and the home.php that opens posts in the single.php template.
- Then, I have to create a different home.php (without header and footer) to show in a webview inside a mobile app, therefore, I need that the posts should open on a different single.php template, also without header and footer, alongside other features not available on the app version.
The site is responsive, so wp_is_mobile is not an option.
How can I do that?
I wonder if I can have two single.php templates for different sources.
The problem is:
- I have the full website, with the blog and the home.php that opens posts in the single.php template.
- Then, I have to create a different home.php (without header and footer) to show in a webview inside a mobile app, therefore, I need that the posts should open on a different single.php template, also without header and footer, alongside other features not available on the app version.
The site is responsive, so wp_is_mobile is not an option.
How can I do that?
1 Answer
Reset to default 0You would use page templates to accomplish what you're doing. If you specify a page-{slug}.php
, it'll use that one instead. It always does upward traversal. So if there's a specific page, it'll use it. If not, it'll be one level more general.
Copy the home.php PHP into your new one, and remove the calls for the header and footer. Voila!
You could also wrap the calls to the header/footer in an is_page()
conditional
if (is_page("slug-name") { get_header() }
<- pseudo code for you to get the idea You'll have to see what all you need to wrap in conditionals for your use case.
More info on using Page Templates: here
body
tag as a class and write CSS based on that. – Tony Djukic Commented Apr 26, 2020 at 17:00