16

On the post edit page, if you fill Excerpt box with any text, the_excerpt() function doesn't add read more link or ... at the end of the short description at frontend. Read more link is only included if Excerpt is set empty. This is not a bug, it's a default behavior. The solution is to avoid the excerpt_more filter to return read more link, and use the ...


14

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 question, feel free to post an answer. Also, if you have any other solutions, feel free to post an answer. REWORKED CLASS AND SOLUTION: What I tried to do here ...


10

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 hook is the first one through which you can use these conditionals). For themes, this means the conditional tag will never work properly if you are using it in the ...


8

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 will add your custom post type to the home page main loop: add_action( 'pre_get_posts', 'wpse_242473_add_post_type_to_home' ); function ...


8

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', ...


7

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 ...


7

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 $...


6

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 settings to use: A static page (select below) instead of Your latest posts If you want is_front_page() to only return TRUE when viewing the page you select ...


5

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( $...


4

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 the home page } As mentioned in the comments, this approach will not work for WP instances installed in subdirectories of the web root. Use at your discretion.


4

When posting a form, if you use 'name' as an input name then there seems to be a problem with submitting. Try changing: <input type="text" name="name" class="form-contact__text" /> to: <input type="text" name="the_name" class="form-contact__text" /> Also, best to give your submit button a more unique name in case it conflicts with any ...


4

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 the current page number (note that this calculation works because posts per page and offset are both 5, you may have to use the posts_per_page value in your ...


4

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('page_id') == get_option('page_on_front') ) { // do stuff } } add_action('pre_get_posts', 'custom_pre_get_posts'); This solution is from here: https://...


4

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->is_home() ) return true; elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( ...


4

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 archive pages and the front page uses paged and not page, so you would need to set get_query_var( 'page' ) to get_query_var( 'paged' ). Any ways, you should not ...


4

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( 'page-templates/front-page.php' ); if ( !$locate_template ) return $template; return $locate_template; });


4

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 your case doesn't behave in same way as other themes typically do. If you run down specific template being used (plugin like Query Monitor can help with this) it'...


4

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 explainer had set the latest posts as the home page (this is the default option) and you have set a static front page as home page. Since his is blog archive, it's ...


4

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 type here 'order' => 'DESC', ); // query $the_query = new WP_Query( $args ); if( $the_query->have_posts() ): while( $the_query->have_posts() ) : $...


4

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 there is no url query parameter to supply a different default using something like this: add_action( 'customize_controls_init', function() { global $...


4

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"> <?php while(have_posts()): the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> </div> <?php get_footer(); ?> UPDATE ...


4

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 you need to do so. Option #1 is more appropriate when you also want to manage some of the front page's content in a regular Editor, rather than in the theme. ...


3

When a theme has the front-page.php template, it will take over regardless of what you set in the admin pages to be your front page. 1 This means you have a couple of options: Create a page template with your loop and styles that are currently part of front-page.php, apply that template to a new page you create in WP, then assign that new page to be ...


3

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, your paginated links code always use paged: ... 'format' => '?paged=%#%', ... So you are sending paged query var but looking for page var. Solution is to ...


3

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() && $query->is_main_query() ) { $query->set( 'meta_query', array( array( 'key' => '_thumbnail_id' ) ) ); } } add_action( 'pre_get_posts', '...


3

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 page_for_posts are 0 when no pages are chosen. You can use update_option to change these values, there is no set_option function.


3

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 your custom content in the same way you would do for a post in the page editor backend. You can then simply use the default loop to display your content as ...


3

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


3

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 template. If you have front-page.php , then please check which header file it is enqueuing. If there is no front-page.php then check home.php exist in your theme ...


3

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 tag and the function should work for both. It's a modification of some code I use in a lot of sites. Put it in your theme's functions.php. Modify the HTML I'...


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