• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Change the number of entries in WordPress latest posts block

Find out in this tutorial how you can change the number of entries displayed in all the latest posts blocks, using code.

The latest posts block is very handy to add, for example, at the end of articles, and its user interface allows you to choose how many posts do you want to display.

But imagine that after you have added dozens (or hundreds) of blocks you decide you want to show less posts on them. This change could take hours.

Luckily, there is a filter that allows you to modify it and save a lot of time. Let’s see how.

Change the number of entries in the WordPress latest posts block in batch

Add the following code at the end of functions.php or in your functionality plugin:

To see this and another 883 code snippets of this website, login or subscribe here.

In this code you use the render_block_data filter to modify the number of posts displayed in the latest posts block (core/latest-posts).

Once applied, all web latest posts blocks will show 3 entries (value that you can modify in the code).

In addition, you can combine this with conditional tags so that you can control how many posts are shown depending on the page (is_front_page, is_page…)

Conclusion

Now you know how to programmatically change the number of entries displayed in the latest posts block.

Any questions? Let me know in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

Block Editor PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?