Filter front page posts by category

Try adding this code to functions.php file: add_action(‘pre_get_posts’, ‘ad_filter_categories’); function ad_filter_categories($query) { if ($query->is_main_query() && is_home()) { $query->set(‘category_name’,’news, uncategorized’); } } category_name is the slug or the nicename of the category. Add a comma separated list of the categories you wish to include.

Facebook comments box on front page

Fast ‘n’ Hacky The problem can be solved by changing line 319 in facebook.php to the following: if (is_home()) { This way, the front page is not treated as a home page but as a regular page, for which the facebook feature settings can be applied (and will be handled correctly). More Elegant/Complex Here is … Read more

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 ( is_page() && $front_page = get_option( ‘page_on_front’ ) ) { if ( is_page( $front_page ) ) $redirect = false; } return $redirect; } add_filter( ‘redirect_canonical’, ‘wpse_184163_disable_canonical_front_page’ ); … Read more

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 \WP_Query class: $orderby = apply_filters_ref_array( ‘posts_orderby’, array( $orderby, &$this ) ); $where = apply_filters_ref_array( ‘posts_where’, array( $where, &$this ) ); $join = apply_filters_ref_array( ‘posts_join’, array( $join, &$this ) ); … Read more

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’, ‘default’ ); get_template_part( ‘front-page’, $layout ); get_footer(); After that you need to create a file for every layout, they should be called, something like: front-page-one.php front-page-two.php front-page-three.php front-page-default.php … Read more

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\RestAPI\Frontpage; \add_action( ‘rest_api_init’, function() { \register_rest_route( ‘wpse/v1’, ‘/frontpage/’, [ ‘methods’ => ‘GET’, ‘callback’ => __NAMESPACE__.’\rest_results’ ] ); } ); function rest_results( $request ) { // Get the ID of … Read more