
Regenerate WordPress media image sizes, programmatically
25/02/2021Learn how to regenerate and update WordPress media and image sizes both programmatically (without plugin), and also with a handy plugin.
So you’ve installed Yoast (or some other plugin) and now your post columns are unmanageable?
This problem is normally caused when you have too many plugins adding to the post columns of the post table view.
Thankfully I have a solution for you!
To begin with we will need to open our theme or plugin functions.php and create a function to handle removing the unwanted columns.
function remove_yoast_columns($columns) {
}
We can then use <a>php unset</a> to remove the entry from the $columns array being passed. I am removing the ‘wpseo-score’ and ‘wpseo-score-readability’ variables.
function remove_yoast_seo_columns($columns) {
// Remove Score
unset($columns['wpseo-score']);
// Remove Score Readability
unset($columns['wpseo-score-readability']);
return $columns;
}
Finally we need to hook a filter to use our remove function. The syntax is as follows:
add_filter('manage_[post_type]_posts_columns', '[function_name]', [priority?]);
For our example the code looks like this:
add_filter('manage_product_posts_columns' , 'remove_yoast_columns', 11);
Congratulations! Your post tables should now be easier to maintain.
N.B. Some other things that you might want to remove (depending on whether you are using them):
// Remove Author
unset($columns['author']);
// Remove Tags
unset($columns['tags']);
// Remove Comments
unset($columns['comments']);
Learn how to regenerate and update WordPress media and image sizes both programmatically (without plugin), and also with a handy plugin.
Need to find a directory path relative to your current file? This is how we use dirname() and realpath() to move up directory levels in PHP.
Ever seen constants like __DIR__ and __FILE__ being used in PHP? These are 'Magic Constants', and this is how we can use them.
What are web components? Learn about web components, the shadow DOM, styling and lifecycle callbacks in this JavaScript tutorial series.
Learn how to use event listeners to detect and handle single and multiple keypress events in JavaScript. Add modifier keys to your application!
Using Bulma but don't know how to integrate it with Nuxt? I'll show you how to load Bulma into your Nuxt project with full control over variables.