When you uninstall plugins from WordPress a lot can be leftover in the database. This makes the database unnecessarily large and could even slow down queries. It is always a good idea to clean your WordPress database after removing plugins. I recently switched a site from Elementor to GenerateBlocks to improve performance so naturally I had to clean up the database.
This tutorial is for the post uninstallation of Elementor to remove leftover rows from the options table, postmeta, usermeta table and posts table.
In this tutorial we will cover the following
- Delete the Elementor plugins and files
- Delete the Elementor post types
- Delete the Elementor taxonomy
- Delete the Elementor meta_keys from usermeta and postmeta
- Delete the Elementor orphaned options from wp_options
Delete Elementor Plugins and Files
Delete the Elementor plugins – this does not include any ultimate add-ons or extra plugins
wp plugin delete elementor --allow-root
wp plugin delete elementor-pro --allow-root
Remove the Elementor uploads folder
rm -rf wp-content/uploads/elementor
Delete Elementor Post Types
We are going to list the post types and see if Elementor is in there
wp post-type list --allow-root | grep elementor
I got no output, let’s search in the database
wp db query "SELECT DISTINCT(post_type) FROM $(wp db prefix --allow-root)posts" --allow-root
There we go, the elementor_library
post type is there!
+---------------------+
| post_type |
+---------------------+
| amn_exact-metrics |
| attachment |
| custom_css |
| customize_changeset |
| download |
| edd_log |
| edd_payment |
| elementor_library |
| gp_elements |
| nav_menu_item |
| oembed_cache |
| page |
| post |
| pretty-link |
| revision |
| wpcf7_contact_form |
+---------------------+
Now we can delete all of the elementor_library
posts
Let’s list them first
wp post list --post_type=elementor_library --post_status=draft,revision,publish --allow-root
Output
+-----+---------------------+---------------------+---------------------+-------------+
| ID | post_title | post_name | post_date | post_status |
+-----+---------------------+---------------------+---------------------+-------------+
| 217 | Default Kit | default-kit | 2020-03-08 00:05:51 | publish |
| 112 | WP Bullet Minify | wp-bullet-minify | 2016-12-10 22:13:29 | publish |
| 64 | Works with template | works-with-template | 2016-10-30 20:02:04 | publish |
| 18 | Home Final Final | home-final-final | 2016-10-26 13:52:42 | publish |
+-----+---------------------+---------------------+---------------------+-------------+
In order to delete these we must use --force
or you will get the error below
Warning: Posts of type 'elementor_library' do not support being sent to trash.
Please use the --force flag to skip trash and delete them permanently.
Here is the command to delete any elementor_library
posts with WP-CLI
wp post delete $(wp post list --post_type=elementor_library --post_status=draft,revision,publish --allow-root --skip-plugins --format=ids) --force --allow-root
You should see some output resembling this
Success: Deleted post 217.
Success: Deleted post 112.
Success: Deleted post 64.
Success: Deleted post 18.
Delete Elementor Taxonomy
When searching the database I spotted that there were Elementor references in the taxonomy tables so let’s make sure we get those too!
Here is the output of searching the database for the elementor
string.
wp_posts:post_type
18:elementor_library
wp_posts:post_type
64:elementor_library
wp_posts:post_type
112:elementor_library
wp_posts:post_type
217:elementor_library
wp_term_taxonomy:taxonomy
5:elementor_library_type
wp_term_taxonomy:taxonomy
6:elementor_library_type
We are going to count the Elementor rows in the taxonomy table
wp db query "SELECT COUNT(*) AS ElementorTaxonomy FROM $(wp db prefix --allow-root)term_taxonomy WHERE taxonomy LIKE '%elementor%'" --allow-root
Output
+-------------------+
| ElementorTaxonomy |
+-------------------+
| 2 |
+-------------------+
Now we can delete those
wp db query "DELETE FROM $(wp db prefix --allow-root)term_taxonomy WHERE taxonomy LIKE '%elementor%'" --allow-root
Done!
You could also usewp term delete
here after listing the existing terms withwp term list
Clean Elementor postmeta
We are going to list the meta_key
rows from the postmeta
table that contain the string elementor
.
wp db query "SELECT DISTINCT(meta_key) FROM $(wp db prefix --allow-root)postmeta" --allow-root | grep elementor
Output
_elementor_data
_elementor_edit_mode
_elementor_template_type
_elementor_version
_elementor_conditions
_elementor_page_settings
_elementor_pro_version
_elementor_template_widget_type
_elementor_global_widget_included_posts
_elementor_template_sub_type
_elementor_popup_display_settings
_elementor_source_image_hash
_elementor_controls_usage
_elementor_css
Let’s count how many Elementor Postmeta there are
wp db query "SELECT COUNT(*) AS ElementorPostMeta FROM $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%elementor%'" --allow-root
Output
+-------------------+
| ElementorPostMeta |
+-------------------+
| 52 |
+-------------------+
Delete all of the Elementor postmeta entries with this query
wp db query "DELETE FROM $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%elementor%'" --allow-root
Now we can clean the usermeta of leftover Elementor data
Clean Elementor usermeta
We can also get rid of any usermeta created by Elementor
wp db query "SELECT DISTINCT(meta_key) FROM wp_usermeta" --allow-root | grep elementor
Look at that, there are a few
elementor_introduction
elementor_admin_notices
wp_elementor_connect_common_data
We can count these too
wp db query "SELECT COUNT(*) AS ElementorUserMeta FROM $(wp db prefix --allow-root)usermeta WHERE meta_key LIKE '%elementor%'" --allow-root
Output
+-------------------+
| ElementorUserMeta |
+-------------------+
| 2 |
+-------------------+
Delete the orphan meta_keys
leftover from Elementor
wp db query "DELETE FROM $(wp db prefix --allow-root)usermeta WHERE meta_key LIKE '%elementor%'" --allow-root
Now on to the options table!
Delete Elementor Options
You can check the amount of autoloaded data on your site the lower the better! I used wp doctor to check.
+-----------------------+---------+--------------------------------------------------------------------+
| name | status | message |
+-----------------------+---------+--------------------------------------------------------------------+
| autoload-options-size | success | Autoloaded options size (116.58kb) is less than threshold (900kb). |
+-----------------------+---------+--------------------------------------------------------------------+
List the options belonging to Elementor
wp option list --field=option_name --allow-root | grep elementor
Output
elementor_active_kit
elementor_allow_svg
elementor_allow_tracking
elementor_beta
elementor_clear_cache
elementor_connect_site_key
elementor_container_width
elementor_controls_usage
elementor_cpt_support
elementor_css_print_method
elementor_custom_icon_sets_config
elementor_default_generic_fonts
elementor_disable_color_schemes
elementor_disable_typography_schemes
elementor_edit_buttons
elementor_editor_break_lines
elementor_enable_inspector
elementor_exclude_user_roles
elementor_font_awesome_pro_kit_id
elementor_fonts_manager_fonts
elementor_fonts_manager_font_types
_elementor_general_settings
_elementor_global_css
elementor_global_image_lightbox
elementor_icon_manager_needs_update
_elementor_installed_time
elementor_library_category_children
elementor_load_fa4_shim
elementor_log
elementor_maintenance_mode_exclude_mode
elementor_maintenance_mode_exclude_roles
elementor_maintenance_mode_mode
elementor_maintenance_mode_template_id
elementor_page_title_selector
elementor_pro_activecampaign_api_key
elementor_pro_activecampaign_api_url
elementor_pro_convertkit_api_key
elementor_pro_donreach_api_key
elementor_pro_donreach_api_url
elementor_pro_drip_api_token
elementor_pro_facebook_app_id
elementor_pro_getresponse_api_key
_elementor_pro_installed_time
elementor_pro_license_key
elementor_pro_mailchimp_api_key
elementor_pro_mailerlite_api_key
elementor_pro_recaptcha_secret_key
elementor_pro_recaptcha_site_key
elementor_pro_recaptcha_v3_secret_key
elementor_pro_recaptcha_v3_site_key
elementor_pro_recaptcha_v3_threshold
elementor_pro_theme_builder_conditions
elementor_pro_tracker_notice
elementor_pro_upgrades
elementor_pro_version
elementor_remote_info_feed_data
elementor_remote_info_library
elementor_remote_info_templates_data
elementor_replace_url
elementor_reset_api_data
elementor_rollback
elementor_rollback_pro
elementor_rollback_pro_separator
elementor_scheme_color
elementor_scheme_color-picker
_elementor_scheme_last_updated
elementor_scheme_typography
_elementor_settings_update_time
elementor_space_between_widgets
elementor_stretched_section_container
elementor_tracker_last_send
elementor_tracker_notice
elementor_typekit-kit-id
elementor_upgrades
elementor_use_mini_cart_template
elementor_validate_api_data
elementor_version
elementor_viewport_lg
elementor_viewport_md
plugin_last_upgraded_date_elementor
plugin_last_upgraded_date_elementor-pro-elementor-pro-php
plugin_last_upgraded_version_elementor
plugin_last_upgraded_version_elementor-pro-elementor-pro-php
widget_elementor-library
Let’s count them all first
wp db query "SELECT COUNT(*) AS ElementorOptions FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%'" --allow-root
79 is quite a few.
+------------------+
| ElementorOptions |
+------------------+
| 79 |
+------------------+
Check if these are autoloaded or not (autoloaded data can slow down your site so make sure to clean it!)
wp db query "SELECT COUNT(*) AS ElementorAutoloaded FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%' AND autoload='yes'" --allow-root
Output
+---------------------+
| ElementorAutoloaded |
+---------------------+
| 75 |
+---------------------+
Delete all of the Elementor settings from the wp_options table
wp db query "DELETE FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%'" --allow-root
Have you found any database rows leftover by Elementor that I missed? Please do share in the comments or use the contact page to get them in here 🙂
Here is a post uninstallation Elementor removal script to clean your WordPress database.
#!/usr/bin/env/bash
# Purpose - clean Elementor leftover database rows from WordPress
# Author - Mike from WP Bullet https://wp-bullet.com
# deactivate and delete
wp plugin deactivate elementor --allow-root
wp plugin deactivate elementor-pro --allow-root
wp plugin delete elementor --allow-root
wp plugin delete elementor-pro --allow-root
# clean up leftover Elementor uploads
rm -rf wp-content/uploads/elementor
# taxonomy
wp db query "DELETE FROM $(wp db prefix --allow-root)term_taxonomy WHERE taxonomy LIKE '%elementor%'" --allow-root
# custom post types
wp post delete $(wp post list --post_type=elementor_library --post_status=draft,revision,publish --allow-root --skip-plugins --format=ids) --force --allow-root
# postmeta
wp db query "DELETE FROM $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%elementor%'" --allow-root
# usermeta
wp db query "DELETE FROM $(wp db prefix --allow-root)usermeta WHERE meta_key LIKE '%elementor%'" --allow-root
# options
wp db query "DELETE FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%'" --allow-root