How to Show Future Scheduled Posts on Your WordPress Website Without 404 Errors

Introducción a la Gestión de Contenido en WordPress

La plataforma WordPress It has established itself as one of the most powerful and versatile tools for creating websites and blogs. Among its many features, one of the most notable is the ability to schedule posts to be published on future dates. However, this feature can present challenges, especially when it comes to displaying these scheduled tickets to visitors before publication. In this article, we will explore how you can do this without causing errors. 404, using different methods such as shortcodes, widgets, blocks Gutenberg and the REST API.

Why Show Future Entries?

Showing future posts can have several benefits for your website. First, it can increase your visitors' interest by allowing them to see what content they can expect in the future. This can be especially useful for blogs that cover trending topics or have a well-defined editorial calendar. Additionally, displaying scheduled content can help maintain engagement on your site, which can have a positive impact on your SEO by reducing the bounce rate.

Methods for Displaying Scheduled Entries

1. Using Shortcodes

Shortcodes are one of the most practical tools in WordPress. To display scheduled entries using a shortcode, you can use the following code in the file functions.php of your topic:

function mostrar_entradas_futuras() { $args = array( 'post_type' => 'post', 'post_status' => 'future', 'posts_per_page' => 5 ); $entradas = new WP_Query($args); if ($entradas->have_posts()) { $output = '
    '; while ($entradas->have_posts()) { $entradas->the_post(); $output .= '
  • '.get_the_title().'
  • '; } $output .= '
'; wp_reset_postdata(); return $output; } add_shortcode('entradas_futuras', 'mostrar_entradas_futuras');

Once this code is added, you will be able to use the shortcode [future_entries] on any page or post on your site to display scheduled posts.

2. Implementing a Custom Widget

Another way to display your future posts is through a widget. You can create a custom widget that displays scheduled entries. This method is ideal if you want scheduled posts to appear in a sidebar area of ​​your site. Here's a basic example of how you could do it:

class EntradasFuturasWidget extends WP_Widget { function __construct() { parent::__construct('entradas_futuras_widget', 'Entradas Futuras'); } public function widget($args, $instance) { $args = array( 'post_type' => 'post', 'post_status' => 'future', 'posts_per_page' => 5 ); $entradas = new WP_Query($args); if ($entradas->have_posts()) { echo $args['before_widget'].'

Entradas Futuras

    '; while ($entradas->have_posts()) { $entradas->the_post(); echo '
  • '.get_the_title().'
  • '; } echo '
'.$args['after_widget']; } wp_reset_postdata(); } }

This widget can be added to any widget area of ​​your theme, allowing your visitors to view future posts in an accessible way.

3. Using the Gutenberg Block

If you prefer a more visual solution, you can use the blocks of Gutenberg. There are specific blocks that allow programmed entries to be displayed. You can search the WordPress plugin repository to find options that fit your needs. For example, plugins like WP Scheduled Posts They offer blocks that make it easy to integrate programmed content into your pages.

4. Accessing the WordPress REST API

For developers looking for a more technical solution, the REST API WordPress allows you to access the information of scheduled entries in a programmatic way. You can make a call to the API to get the messages with the status “future”, which will allow you to display this information anywhere on your site, or even integrate it into external applications. Here's a basic example of how you could do it:

fetch('https://tuwebstartup.com/wp-json/wp/v2/posts?status=future') .then(response => response.json()) .then(data => { data.forEach(post => { console.log(post.title.rendered); }); });

Tips to Avoid 404 Errors

It is essential to ensure that scheduled entries do not generate 404 errors. To achieve this, ensure that your links and permalinks are configured correctly. It is also advisable to review your server configuration and the write-back rules in your file .htaccess to avoid access problems. By doing so, you will not only improve the user experience, but you will also contribute to better SEO performance of your site.

Conclusion

Showing scheduled future posts on your WordPress site is not only possible, but can be an effective strategy to increase the anticipation and engagement of your visitors. From using shortcodes to the REST API, the options are diverse and suit different levels of technical skill. For more information on how to optimize your website, we invite you to explore our categories of web design and development Y SEO web positioning.

Fuente original: How to show future scheduled entries to your visitors

Picture of Web design in Valencia Tu Web Startup

Web design in Valencia Tu Web Startup

Facebook
X
LinkedIn