WordPress
Contents
Cleanup Database
To delete orphaned post meta, use this query:
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT ID FROM wp_posts);
To delete post meta from revisions, use this query:
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'revision');
Finally, delete the revisions from your database:
DELETE FROM wp_posts WHERE post_type = 'revision';
Custom Post Types with SVG menu icon
To use SVG icons for your Custom Post Types in WordPress, encode the SVG in base64. Make sure that your SVG includes currentColor
to match the WordPress menu.
register_post_type(
'product',
[
'menu_icon' =>
'data:image/svg+xml;base64,' .
base64_encode(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M11.644 1.59a.75.75 0 0 1 .712 0l9.75 5.25a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.712 0l-9.75-5.25a.75.75 0 0 1 0-1.32l9.75-5.25z"/><path d="m3.265 10.602 7.668 4.129a2.25 2.25 0 0 0 2.134 0l7.668-4.13 1.37.739a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.71 0l-9.75-5.25a.75.75 0 0 1 0-1.32l1.37-.738z"/><path d="m10.933 19.231-7.668-4.13-1.37.739a.75.75 0 0 0 0 1.32l9.75 5.25c.221.12.489.12.71 0l9.75-5.25a.75.75 0 0 0 0-1.32l-1.37-.738-7.668 4.13a2.25 2.25 0 0 1-2.134-.001z"/></svg>'
),
],
);
Plugins
-
I use this plugin for custom fields in post types and Gutenberg blocks. I combine it with Extended ACF, which allows me to add fields using object-oriented PHP for better version control of the fields.
-
Räksmörgås.jpg → raksmorgas.jpg
-
Not a plugin per se, but a library that offers enhanced functionality for custom post types and taxonomies.
-
The plugin removes a lot of default WordPress stuff you just can’t wait to get rid of.
-
Make your site’s pages instant in 1 minute and improve your conversion rate noticeably.
-
For multilingual websites.
-
Easily and safely manage your site’s redirects the WordPress way.
-
The name suggests that it only works for custom post types, but it also works for taxonomies.
-
The SEO plugin, is ad-free, banner-free, open source, and it simply works.
-
I usually take crontrol and disable WordPress’s own cron system. Instead, I set up a custom cron job.
Update URLs
To update URLs in your database, use the following queries:
UPDATE wp_options SET option_value = REPLACE(option_value, 'old.com', 'www.new.com');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'old.com', 'www.new.com');
UPDATE wp_posts SET guid = REPLACE(guid, 'old.com', 'www.new.com');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'old.com', 'www.new.com');