How to clean a wordpress theme. Remove remnants of deleted wordpress plugins. Removing plugins and themes shortcodes

If you have a WordPress website and you have never or never cleaned the database for a long time, then now is the time to do it.

If you haven’t cleaned the database for a long time, most likely it is filled with unused records, which increase its size and this slows down the site.

In this post, you will learn several SQL queries for manual cleaning and database optimization, and several plugins for automatic database cleaning.

Before you start, make a backup. If something goes wrong, you can restore the database from the backup.

Remove unused plugins. Remove all plugins that you are not using. Remains from remote plugins are one of the sources of garbage.

  How to make SQL database queries

For database administration, the phpMyAdmin application is usually used, which is launched from the hosting panel. Search for “Database,” “Database,” “MySQL,” or something similar. Open the desired database.

If you forgot or don’t know the name, username or password for your database, you can find them in the file wp-config.phpwhich is located in the root folder of the site. Database entries are at the very beginning of the file.

If you have Russian language:

If you have English:

  database_name,   login-to-database,   DB password  - copy the username and password and open the database.

Queries are created on the SQL tab. Documentation

Make inquiries here. When the request is ready, click Forward.

If you get an answer that 0 tables have been changed, then the current state of the parameter corresponds to the query.

  Inquiries

Use these SQL queries to clean up the database.

  Removing data from deleted plugins and post data

After removing unnecessary plugins, entries from them may remain in the wp_postmeta table. In the same table are the meta data of posts.

Create a query on this table to remove unused plugin and post entries that remain after removing plugins or posts.

DELETE FROM wp_postmeta WHERE meta_key \u003d ‘ your meta key‘;

Replace your meta key  to the desired value.

For multisite:

DELETE FROM wp _ # _ postmeta WHERE meta_key \u003d ‘ your meta key‘;

Change #   on the site ID and your meta key  to the desired value.

  Removing spam comments

You can remove all spam from the database with this request:

spam‘;

For multisite:

spam‘;

Change # to site ID.

Delete pending comments

If you have a lot of spam pending review, you can delete it with this request. Before deleting, make sure that the necessary comments are not deleted.

DELETE FROM wp_comments WHERE comment_approved \u003d ‘ 0 ‘;

For multisite:

DELETE FROM wp _ # _ comments WHERE comment_approved \u003d ‘ 0 ‘;

Change # to site ID.

  Removing Unused Tags

If you have a tag that is not associated with any article, delete it with this request:

DELETE FROM wp_terms wt

For multisite:

DELETE FROM wp _ # _ terms wt
  INNER JOIN wp_term_taxonomy wtt ON wt.term_id \u003d wtt.term_id WHERE wtt.taxonomy \u003d ‘post_tag’ AND wtt.count \u003d 0;

Change # to site ID.

  Removing Trackback and Pingback

If you turned off these features and want to remove their entries from the database, use these queries:

  Trackback

trackback‘;

For multisite:

trackback‘;

Change # to site ID.

  Pingback

DELETE FROM wp_comments WHERE comment_type \u003d ‘ pingback‘;

For multisite:

DELETE FROM wp _ # _ comments WHERE comment_type \u003d ‘ pingback‘;

Change # to site ID.

You can disable these features in WordPress in Settings -\u003e Discussions.

  Delete post revisions

Saved versions of posts are stored in the database. If you have a large site, a large number of revisions greatly increases its size. To delete them all use this query:

DELETE a, b, c FROM wp_posts a
  LEFT JOIN wp_term_relationships b ON (a.ID \u003d b.object_id)
  LEFT JOIN wp_postmeta with ON (a.ID \u003d c.post_id)
  LEFT JOIN wp_term_taxonomy d ON (b.term_taxonomy_id \u003d d.term_taxonomy_id)

For multisite:

DELETE a, b, c FROM wp _ # _ posts a
  LEFT JOIN wp _ # _ term_relationships b ON (a.ID \u003d b.object_id)
  LEFT JOIN wp _ # _ postmeta with ON (a.ID \u003d c.post_id)
  LEFT JOIN wp _ # _ term_taxonomy d ON (b.term_taxonomy_id \u003d d.term_taxonomy_id)
  WHERE a.post_type \u003d ‘revision’
  AND d.taxonomy! \u003d ‘Link_category’

Replace # with the site ID.

  Removing plugins and themes shortcodes

If you used some kind of plugin that inserts shortcodes, or you changed the theme in which shortcodes were built in, now shortcodes will appear on the site as text. To remove all shortcode entries from the database, make this request:

UPDATE wp_post SET post_content \u003d replace (post_content, ‘ [your shortcode]‘, »);

For multisite:

UPDATE wp _ # _ post SET post_content \u003d replace (post_content, ‘ [your shortcode]‘, »);

Change # to site ID.

  Delete posts older than X days

If you want to delete posts older than X days, use this query:

DELETE FROM ‘wp_posts’
  WHERE ‘post_type’ \u003d ‘post’
  AND DATEDIFF (NOW (), ’post_date’)\u003e X days

ReplaceX-days  for the right number of days.

For multisite:

DELETE FROM ‘wp _ # _ posts’
  WHERE ‘post_type’ \u003d ‘post’
  AND DATEDIFF (NOW (), ’post_date’)\u003e X-days

Change # andX-days.

  Delete other comments

Sometimes some plugins add comments to the wp_commentsmeta table instead of wp_comments. If you want to clear this table, use this query:

SELECT FROM wp_commentsmeta WHERE comment_id
  NOT IN (
  SELECT comment_id
  FROM wp_comments
);

If you want to clear the wp_commentsmeta table on another site on the network, use this query:

SELECT FROM wp _ # _ commentsmeta WHERE comment_id
  NOT IN (
  SELECT comment_id
  FROM wp _ # _ comments
);

Replace # with the site ID.

  Database of fresh installation Wordpress 4.9.8 for comparison

  Table optimization

You can optimize database tables without using plugins.

In phpMyAdmin select the database you need, go down, click Select all  and select from the dropdown menu. You don’t need to click “Forward”; optimization will start automatically.

If your database does not fit on one page, then you need to optimize the tables on each page. You can optimize all tables, or only the largest in size. The size of the table is indicated in the Size column.

A blank result means that nothing has been optimized, because the tables are already optimized by the plugin that is installed on the site.

  WordPress Plugins for Database Optimization

4 best database optimization plugins in order of increasing functionality.

Back up the database before using these plugins. Some of the plugins delete posts with a draft status. Make sure all Drafts are published.

  WP Sweep

Hope the article was helpful. Leave a comment.

Hello, dear readers of the blog www.site. If the texts of articles on a site running on WordPress CMS, then very soon the volume of the site database will increase many times over.

The fact is that starting with version 2.6, a very useful and necessary mechanism for revising (editing) posts has been added to WordPress.

The fact that this option is needed is beyond doubt. Offhand, you can imagine several possible reasons for losing the current contents of the edited record. This may be a network failure at the time of the update, overwriting by the obsolete version when editing from different places (I had this), an elementary error of the editor, and so on.

WordPress Revision  they allow to avoid data loss due to the fact that all previous versions of records are not deleted from the database, but only receive a different status - “ revision»

In the word “all” of the previous paragraph lies precisely the reason for the unlimited growth in the size of the database. Each revision (revision) of the record contains its full content. This means that if during the preparation of an article you corrected and rewritten it, say, 10 times, then 10 copies will be stored in the database. If you correct only one character, the entire text will be added to the database again.

Despite the fact that the increase in the volume of the database, perhaps, does not lead to a noticeable decrease in the speed of the site’s response, it seems incorrect and inappropriate to keep any data that is no longer needed in it.

It is strange that after the inclusion of the editorial mechanism in WordPress, no reasonable limitation of their number was immediately made. Doing it yourself is very simple.

WordPress post revision management

To control the mechanism for saving post edits in WordPress to a configuration file “ wp-config.php”After:
  / ** The Database Collate type. Don "t change this if in doubt. * /
  define ("DB_COLLATE", ""); only one entry needs to be added.
  To limit the number of editions to three copies:
  define ("WP_POST_REVISIONS", 3); Instead of “3” there can be any value you need. “0” will disable saving revisions. The same result will be achieved if instead of the number write “false”:
  define ("WP_POST_REVISIONS", false);
  If for any reason you need to re-enable all editions to be saved without deleting this line from “ wp-config.php”, Then you can write:
  define ("WP_POST_REVISIONS", true);

WordPress Post Revision Type

In turn, the editorial offices are divided into two categories:

  1. editorial revisions  - previous versions of texts that appeared after publication or saving by the editor (author) of the updated record;
  2. autosaved revisions  - are automatically created at certain time intervals.

How interesting. While writing this post I noticed an interesting feature. If the entry is in the “Draft” status, then it does not have autosaved editions. It turns out that autosaving does not apply to the draft. Therefore, you should not forget to click on “Save” when working with a draft in the WordPress editor.

The number of autosaved editions for recording is always equal to one. That is, if you set the total number of editions to be kept equal to, for example, three, then two of them will be copyrighted. Autosaved revisions never overwrite copyright ones.

Auto-save allows you not to lose recently collected data in the event that the author forgot to save them forcibly (it turns out that this does not apply to the draft).

You can change the autosave interval by adding “ wp-config.php”Line:
  define ("AUTOSAVE_INTERVAL", 60); where 60 is the interval in seconds corresponding to the default one. It can be adjusted in any desired direction.

After adding these simple settings, the WordPress database will immediately decrease to the size corresponding to the number of revisions and will never grow like mushrooms after rain.

If you need to remove all releases, you can do this without installing plugins directly in the MySQL database via phpMyAdmin.

We go into phpMyAdmin and select the desired base in the left column of the interface. We begin, naturally, with.

Backup database

Go to the “Export” tab:

In the window that opens, leave the settings unchanged. Click “OK” in the lower right part of the screen and wait for the completion of the operation to save the backup database.

Database queries for deleting revisions and optimizing the wp_posts table

Go to the “SQL” tab. In the field of database queries, write:
  DELETE FROM wp_posts WHERE post_type \u003d "revision";
  OPTIMIZE TABLE wp_posts;

Click “OK”, confirm the desire to fulfill queries to the database.

After successful completion of requests, a message of the following type should appear:

If desired, you can write and execute queries sequentially.

If we again look at the size of the database after the operations done (for the simplest comparison, you can repeat the backup of the database to a new file without leaving phpMyAdmin), you can be sure to make sure that it has decreased several times.

Personally, I would already stop there - the maximum number of saved releases is configured, the database is cleaned and optimized. If you wish, after a certain period of time, determined by the amount of text changes made on the site, you can repeat the cleaning of the database in the described way.

In touch Ilya Zhuravlev,after reading this article, you will learn how to clean and optimize the wordpress database. Over time, a lot of unnecessary garbage accumulates in the database, which can affect, for example, the speed of opening your site. The database is loaded not only with the installed plugins, but when you remove the plugin, it may leave the wrong code, tables, rows. Not many people know about post revisions, when you write an article, then wordpress, every time you change a post, automatically saves a draft post in the database. Imagine how many such drafts are saved when writing one article.

Those who are not engaged in optimization, then their garbage in the database exceeds 2, or even 3, 4, 5 times the size of the main content of the database. Imagine that your database weighs 90 megabytes, but the necessary and main content of the database weighs only 30 megabytes, 60 megabytes is a load of 200, that is, a dead load, unnecessary garbage. Remove this cargo and your site will fly like a falcon!

Let's start cleaning and optimizing the database.

First, clean the database using the plugin - WP Clean Up, a very simple and intuitive plugin, does not need settings, click on the button and that's all, the best of its kind. You can install this plugin directly from the wordpress admin panel. Go to the tab: Plugins - Add new, enter the name of the plugin in the search form, press Enter, install and activate the opened plugin.

To configure the plugin, go to the tab: Settings - WP Clean Up.

On the plugin page, the first field will display the types of database tables that can be cleared. At the bottom, click on the button - Delete All, to immediately clear everything. Attention!  If your site has the drafts you need, then when you clear all the elements at the same time, they will also be deleted. To save Drafts, delete all elements separately, except for the Draft element, by clicking on the Delete button, opposite the value.

In the second field, you will see all the available tables in your database and their size. After cleaning, you will need to optimize the databases, that is, upgrade. Click on the button - Optimize. In the Total field, you can see how much your database has changed in size.

As you can see from the screenshot, in the second table I have only 11 main database tables displayed. You can have much more tables from 50 to 100. In addition to 11 main tables, there are tables related to installed plugins and to remote ones. Next, I will show how to clear the database from unnecessary tables of remote plugins. After cleaning the database, you can deactivate the plugin - WP Clean Up. Periodically, every 3-6 months, activate the plug-in and clean it again.

Hello, friends. Today, with this publication I want to continue the series of articles devoted to the cleaning of computer garbage. I already wrote a couple of articles on this topic.

Today's post will be a small but very useful addition to the article "" written a long time ago. It will be about an addition to the program cleaning system from debris, namely about CCEnhancer.

Cleaning system from debris. Ccleaner + CCEnhancer

To begin, I suggest you read the first article about Ccleaner to establish and understand how to use it. You can download the CCEnhancer plugin. There is an archive exe fileby running which you will see a window for downloading the latest version of this plugin. Click on the button here Download Latest

and look forward to downloading and installing the extension.
Note:

For the CCEnhancer plugin to work, the system must have installed .NetFramework. I wrote about him in the note ""

What does this plugin give us? After installation in the program Cleaner  on the menu Cleaning  on the tab Applications  support for a bunch of new applications is added, or rather 270 applications . But not all of them are displayed on this tab. Only those applications that are currently installed on your system are displayed, or were once installed and then deleted ( unless of course they are on the list of 270 applications) The program works as before. By checking the necessary applications or all at once, we start the process cleaning system from debris.

The program frees up quite a lot of space that was taken computer trash. In relation to all kinds of settings for programs, applications and utilities, their profiles behaves correctly and does not delete the superfluous, necessary.
  Using Ccleaner  paired with Wise disc cleaner  works wonders in terms of cleaning system from debris. About the program Wise disc cleaner  I wrote in the article “

If you have been using WordPress for a long time, then chances are that you should clean your site. Regular cleanings will allow you to reduce the size of your data pack, which in turn will mean fast and small backup files. In today's article, we will show you how to clean up a WordPress database.

As you use WordPress, your database accumulates a lot of additional data, such as post revisions, spam comments, plugin data that you no longer use, and much more. Removing this unnecessary data can significantly reduce the size of your database, which will speed up the backup process and add a little performance to the site. At a minimum, it simply does not make sense to store data in a database that will never be used subsequently.

Let's look at ways to “clean up” your WordPress database.

Make backup before you start!

Before you do anything, first make a full backup of your site. Changes made by the garbage collection plugin are irreversible. Even if these changes do not affect your posts or comments, it is always better to play it safe.

Clean Up Your WordPress Database With WP-Sweep

First of all, you will need to install and activate the WP-Sweep plugin. After activation, just go to the section Tools »Sweep  to clean your database.

The plugin will analyze your WordPress database and display a report on how much garbage you can clean. The plugin report is divided into various sections for entries, comments, user metadata, options, terms and database optimization.

You can examine each element in detail and clean them one by one, or you can scroll down the page and click on sweep all to clear all the garbage in your WordPress database.

Cleaning may take some time depending on how big your database is. WP-Sweep will display progress by updating statistics on the page.

Advantages of WP-Sweep over WP-Optimize?

You might be wondering why we are writing about WP-Sweep when there is another very popular WP-Optimize plugin that performs essentially the same functions.

Also, the main distinguishing feature is that WP-Sweep uses the correct WordPress removal features as much as possible instead of directly executing MySQL queries.

What cleans up WP-Sweep?

WP-Sweep uses the correct WordPress uninstall features to clean the database. At the time of this writing, he is doing the following:

  • Editions of entries
  • Auto Saved Drafts
  • Deleted Comments
  • Unconfirmed comments
  • Spam comments
  • Unused Record Metadata
  • Unused Comment Metadata
  • Unused user metadata
  • Unused term relationships
  • Unused terms
  • Duplicate Record Metadata
  • Duplicate Comment Metadata
  • Duplicate User Metadata
  • Intermediate variations
  • Database table optimization
  • OEmbed cache in record metadata

That's all, we hope this article helped you clean out the trash from your WordPress site using WP-Sweep.

For all questions and feedback, please write in the comments below.

If possible, do not forget to rate your favorite entries by the number of stars at your discretion.


Top