14 votes
Accepted

Using pre_get_posts on true pages and static front pages

I finally got it working, but not with the code in my question. I totally scrapped that whole idea and restarted going in a new direction. NOTE: If anyone is ever able to sort out the issues in my ...
user avatar
10 votes

is_front_page only works in theme file, and does not work in functions.php

The codex quote by chrisguitarguy is no longer valid!! It has been updated to: Warning: You can only use conditional query tags after the posts_selection action hook in WordPress (the wp action ...
user avatar
8 votes

How to put custom post types on front page

Edit: This answer was written before I realised the OP has a static front page. I've left it here in case it's useful to anyone else and added a second answer for the static front page case. This ...
user avatar
8 votes

How do I fetch the static front page using the REST API?

We could implement our own endpoint: https://example.tld/wpse/v1/frontpage Here's a simple demo (PHP 5.4+): <?php /** * Plugin Name: WPSE - Static Frontpage Rest Endpoint */ namespace WPSE\...
user avatar
  • 64.5k
7 votes
Accepted

Ways to have multiple front-page.php templates that can be swapped out?

One way is to have a single front-page.php and then using get_template_part(), to show different content based on user choice. Rough code: get_header(); $layout = get_option( 'front_page_layout', '...
user avatar
  • 44.8k
7 votes
Accepted

How to prevent the default home rewrite to a static page

The redirect is thanks to redirect_canonical() - we can simply swoop in with a filter and disable it for the front page: function wpse_184163_disable_canonical_front_page( $redirect ) { if ( ...
user avatar
  • 35.7k
6 votes
Accepted

Is_front_page inside header.php is always returning true

Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand: if( is_front_page() ){ echo 'Front page!'; } You must have it configured in the ...
user avatar
  • 2,713
5 votes
Accepted

What is the correct method for determining 'is_front_page' when using filters such as 'pre_get_posts' and 'posts_where'?

Regarding the posts_orderby, posts_where, posts_join and posts_clauses hooks, the current \WP_Query object is available through the second input argument. These are the relevant parts from the \...
user avatar
  • 64.5k
5 votes
Accepted

Pagination causes error 404 when used with front-page.php

EDIT From your comments, front-page.php is only used when a page is set as a static front page. Normal home pages, ie, when Front page displays is set to Your latest posts, index.php is used. All ...
user avatar
4 votes
Accepted

Trying to exclude first 5 posts from the first page on the homepage

offset overrides pagination, because when you get down to the query level, it's paginated via offset. You can still use offset though, you just have to do some math to multiply your desired offset by ...
user avatar
  • 76.3k
4 votes

When to use is_home() vs is_front_page()?

I've discovered that is_home() and is_front_page() don't deliver what's expected for multisites. My workaround using built in PHP goodies: if($_SERVER['REQUEST_URI'] == '/') { // you must be on ...
user avatar
4 votes

What is the correct method for determining 'is_front_page' when using filters such as 'pre_get_posts' and 'posts_where'?

instead of $query->is_front_page() try using $query->get('page_id') == get_option('page_on_front') (in context:) function custom_pre_get_posts( $query ) { if ( $query->get('...
user avatar
4 votes
Accepted

How to target only the front page (not subsequent paginated pages) in theme/plugin?

You have a misconception about is_front_page(). Lets look at the source: public function is_front_page() { // most likely case if ( 'posts' == get_option( 'show_on_front') && $this-&...
user avatar
4 votes
Accepted

Load front-page.php from subfolder

You can make use of the frontpage_template filter to adjust where your template should be loaded from add_filter( 'frontpage_template', function ( $template ) { $locate_template = locate_template(...
user avatar
4 votes

How does WordPress decide what template to use as frontpage

Front page template logic is horrendous legacy mess. While back I wrote a very thorough front page cheatsheet, I still can't completely remember how it works. You are right to notice that theme in ...
user avatar
  • 98k
4 votes
Accepted

Theme's page.php and index.php template files are confusing me

WordPress Template Hierarchy: You should read about WordPress template hierarchy. This question also has some related answers. Typical Case: In your case, the most likely scenario is: The ...
user avatar
  • 1,149
4 votes
Accepted

Loop on front-page.php

This is how you would do it. You're loop is based on being in an archive or index page. (or home) $args = array( 'posts_per_page' => 3, 'post_type' => 'post', //choose post ...
user avatar
  • 5,372
4 votes
Accepted

Set Default Page On Customizer Live Preview

The default URL being previewed is home_url( '/' ). When no url query parameter is present when opening customize.php, this is the preview URL that is used. You can override the previewed URL when ...
user avatar
  • 3,930
4 votes
Accepted

My custom template page not loading content inside it?

you have to use the WP Loop to get page content. Try this <?php /* Template Name: home */ get_header(); ?> <div id="theme-main-banner" class="banner-three gradient-banner-three"> <?...
user avatar
4 votes
Accepted

How to display 3 different loops in 3 columns on homepage

There's a third option, creating a front-page.php template file. It's similar to your option #1, except option #1 includes you creating a Page within the admin, and in your case it doesn't sound like ...
user avatar
  • 8,711
3 votes
Accepted

Paginated pages are showing correct content but pagination links are not

Static pages doesn't work with paged query variable, they need the page variable. This is the reason why your second code block makes the query work: it uses the page var when available. However, ...
user avatar
  • 44.8k
3 votes
Accepted

How to show only posts with images?

No need for post IDs what has no thumbnail. Use meta query to get only those what has thumbnail. Add meta query function get_only_posts_with_images( $query ) { if ( $query->is_home() &&...
user avatar
3 votes
Accepted

How do I set the front page programmatically?

If you manually enter the admin URL wp-admin/options.php you'll see a list of all options and their values. show_on_front is page when a page is selected to show on front. page_on_front and ...
user avatar
  • 76.3k
3 votes
Accepted

Can you select a post as the front page or only pages?

No, you cannot. Static front pages needs a page template to be set. You have a couple of choices here to do what you want Create a page you would want select as static front page. You can then add ...
user avatar
3 votes
Accepted

How to set wp_options in functions.php for removeing the Default Front Page

You can use following: update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', '0' ); I hope this helps.
user avatar
3 votes
Accepted

Wordpress, how to figure out how to edit front page

In WP, you first need to understand the template hierarchy https://developer.wordpress.org/themes/basics/template-hierarchy/ So as per hierarchy, -- front-page.php -- home.php / custom page ...
user avatar
  • 1,226
3 votes
Accepted

Custom query_var causes displaying posts archive on front page

After detailed debugging of WP::parse_request() and WP_Query::parse_query() I found out that unset( $query_vars['date'] ); in 'request' filter helps. It basically unsets date query var before ...
user avatar
3 votes
Accepted

How to put custom post types on front page

So if you've registered a CPT called wpse_242473_custom_post_type you can use this to put 6 recent posts of that type onto your static front page (or anywhere). You can use a shortcode or a template ...
user avatar
3 votes
Accepted

Home link in the homepage of my wordpress does not show my blog posts

In Settings -> Reading -> Front page displays select Your latest posts. Go to Appearance -> Menus. You'll see as the first item Home, which points to the physical page 'Home'. Remove Home item from ...
user avatar
3 votes
Accepted

if I create 'front-page.php', then how do I link to post index?

Since WordPress 4.5 you can use get_post_type_archive_link( 'post' ) to link to the page containing the blog posts. Depending on what you've set under Settings -> Reading, this will be either the ...
user avatar
  • 3,654

Only top scored, non community-wiki answers of a minimum length are eligible