Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#39299 closed enhancement (worksforme)

Twenty Seventeen: Allow child themes use Page Template as a front page

Reported by: samikeijonen's profile sami.keijonen Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Bundled Theme Keywords:
Focuses: template Cc:

Description

In Twenty Seventeen we use frontpage_template filter like this

function twentyseventeen_front_page_template( $template ) {
	return is_home() ? '' : $template;
}
add_filter( 'frontpage_template',  'twentyseventeen_front_page_template' );

But this means that child themes can't use Custom Page Template as a front page if they want because front-page.php would always win over any page templates.

  1. Create a child theme.
  2. Create custom page template.
  3. Try to set that as front page. You can't because front-page.php always wins.

In client/custom sites Custom Page Template as front page would be nice to have so that you don't have to override front-page.php logic.

I'll add patch in a minute.

Attachments (1)

39299.1.patch (1.4 KB) - added by sami.keijonen 7 years ago.

Download all attachments as: .zip

Change History (7)

#1 in reply to: ↑ description @JPry
7 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Replying to sami.keijonen:

But this means that child themes can't use Custom Page Template as a front page if they want because front-page.php would always win over any page templates.
...
I'll add patch in a minute.

No need for a patch. A child theme (or plugin) just needs one line:

<?php
remove_filter( 'frontpage_template',  'twentyseventeen_front_page_template' );

Just make sure that filter is applied on the after_setup_theme action (or later).

Alternatively, you can create your own function and hook it to the frontpage_template filter to override what Twenty Seventeen is doing.

Last edited 7 years ago by JPry (previous) (diff)

#2 @sami.keijonen
7 years ago

Well that's one option. But why not set an example how it should be done for parent themes that do want to

  1. have same front-page.php logic.
  2. But still allow users to set Page Template as front page.

#3 @ocean90
7 years ago

@davidakennedy What are your thoughts on this?

#4 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review deleted

#5 @ocean90
7 years ago

#39740 was marked as a duplicate.

#6 @davidakennedy
7 years ago

Sorry I missed this initially. I looked into this while investigating #39740.

I'm in agreement that this should be closed worksforme because this is the default behavior of WordPress. Even if the theme isn't a child theme, front-page.php will always win. That's the purpose of it.

Note: See TracTickets for help on using tickets.