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:
In this code you use the
render_block_data filter to modify the number of posts displayed in the latest posts block (
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 (
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. 😉