If your blog is a few years old and at a certain point you switched to the Gutenberg editor, leaving all those old posts published in the classic editor format, you may want to convert them now to Gutenberg blocks in one go.
Doing this migration can offer some SEO and performance benefits. These are explained at the end of this post.
Convert to Blocks The only decent plug-in left to facilitate this conversion is Convert To Blocks . Just install it. It doesn't have any settings or admin area, nor does it need one.
Now, when you open the list of entries, you will find a new column to the right of the title that tells you whether the entry was published using the Classic Editor or the Gutenberg Block Editor. However, there is a lack of a way to sort them.
It's not that great because this can be done with a function that will add a column on the right showing "Classic" or "Gutenberg" to each post. Something like this:
// Añadir la columna personalizada en la lista de entradas que muestre si fueron publicadas con el editor Clásico o Gutenberg
function add_editor_type_column($columns) {
$columns['editor_type'] = 'Editor';
return $columns;
}
add_filter('manage_posts_columns', 'add_editor_type_column');
// Mostrar el contenido de la columna personalizada
function display_editor_type_column($column_name, $post_id) {
if ($column_name === 'editor_type') {
$content = get_post_field('post_content', $post_id);
if (strpos($content, '<!-- wp:') !== false) {
echo 'Gutenberg';
} else {
echo 'Clásico';
}
}
}
add_action('manage_posts_custom_column', 'display_editor_type_column', 10, 2);
// Hacer que la columna sea ordenable
function make_editor_type_column_sortable($columns) {
$columns['editor_type'] = 'editor_type';
return $columns;
}
add_filter('manage_edit-post_sortable_columns', 'make_editor_type_column_sortable');
// Modificar la consulta para ordenar por el tipo de editor
function sort_posts_by_editor_type($query) {
if (!is_admin() || !$query->is_main_query()) {
return;
}
if ($query->get('orderby') === 'editor_type') {
$query->set('meta_key', '_editor_type');
$query->set('orderby', 'meta_value');
}
}
add_action('pre_get_posts', 'sort_posts_by_editor_type');
// Guardar el tipo de editor como metadato al guardar el post
function save_editor_type_metadata($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
$content = get_post_field('post_content', $post_id);
$editor_type = (strpos($content, '<!-- wp:') !== false) ? 'gutenberg' : 'classic';
update_post_meta($post_id, '_editor_type', $editor_type);
}
add_action('save_post', 'save_editor_type_metadata');
The interesting thing about the plugin is that it converts "on the fly". This means that if you edit any post, it will automatically convert to Gutenberg when you open the editor. If something goes wrong you can see it and exit without saving, discarding the changes to edit what you suspect caused the conversion error and try again.
This is fine for converting a few dozen posts. It works very well and successfully converts almost all of the posts I tested it on. Convert to Blocks warns that by default it will not convert your custom blocks.
Bulk or batch conversion But what if you have hundreds or thousands, as was my case, of posts to convert? This is where the most useful feature of the plugin comes into play. It allows for bulk conversion using WP-CLI . If you already know how to use WP-CLI, you can skip this bit and if you don't, you can go to this link .
On their GitHub page you can find the list of commands you can use.
NOMBRE
wp convert-to-blocks start
DESCRIPCIÓN
Inicia una nueva Migración. El comando imprime la URL que debe abrirse en un navegador para conectarlo a la CLI de WP.
SYNOPSIS
wp convert-to-blocks start [--post_type=<post_type>] [--per_page=<per_page>] [--page=<page>] [--only=<only>] [--catalog] [--reset]
OPCIONES
[--post_type=<post_type>]
Lista opcional delimitada por comas de los tipos de entrada a migrar. Por defecto post,page
[--per_page=<per_page>]
Número opcional de posts a migrar por lote. Por defecto no hay límite. Combinar con --page para paginar.
[--page=<page>]
Número de página opcional desde el que iniciar la migración. Por defecto es 1.
[--only=<only>]
Lista opcional delimitada por comas de ID de post a migrar.
[--catalog]
Bandera opcional para migrar sólo las entradas etiquetadas del editor clásico. Requiere que el plugin Block Catalog esté presente y haya sido indexado.
[--reset]
Detiene cualquier migración en curso y restablece el estado de la migración.
NOMBRE
wp convert-to-blocks stop
DESCRIPCIÓN
Detiene la migración en curso si está activa.
NOMBRE
wp convert-to-blocks status
DESCRIPCIÓN
Imprime el estado de la migración en curso.
If you have a shared hosting or simply don't want to slow down the loading speed because of the high CPU usage of the conversion (keep in mind that it doesn't only convert, it must also save/publish all the posts one by one) I advise you to do it in batches.
I chose the option of converting a certain number of posts by adding blocks of about 100 IDs in each batch.
We know how to see the ID of a post because in the edition it appears in the URL, but now we need to extract all the IDs of the posts published with the classic editor separated by a comma without spaces.
I also have a function for that.
// Función para obtener los IDs de posts creados con el editor clásico
function obtener_ids_posts_editor_clasico() {
global $wpdb;
// Consulta para obtener los IDs de los posts que NO contienen bloques de Gutenberg
$query = "
SELECT ID
FROM {$wpdb->posts}
WHERE post_content NOT LIKE '%<!-- wp:%'
AND post_status = 'publish'
AND post_type = 'post' -- Solo posts, excluye páginas y otros tipos
AND post_content != '' -- Excluye posts vacíos
AND post_title != '' -- Excluye posts sin título
AND post_name != '' -- Excluye posts sin slug válido
";
$results = $wpdb->get_col($query);
// Convierte el array de IDs en una cadena separada por comas
$ids_comma_separated = implode(',', $results);
return $ids_comma_separated;
}
// Shortcode para mostrar el listado de IDs y el número total de posts con el editor clásico
add_shortcode('listado_ids_clasico', function() {
// Obtener la lista de IDs
$ids_posts_clasico = obtener_ids_posts_editor_clasico();
// Contar el número total de IDs
$total_posts = count(explode(',', $ids_posts_clasico));
// Mostrar el contador y la lista de IDs
return 'Total de posts creados con el editor clásico: ' . $total_posts . '<br>IDs de posts: ' . $ids_posts_clasico;
});
Uso:
1. Copia el código en el archivo functions.php de tu tema o en un plugin personalizado.
2. Inserta el shortcode [listado_ids_clasico] en cualquier página o entrada de WordPress no hace falta que la publiques. Te bastará hacer una vista previa del borrador.
3. El shortcode mostrará el número total de posts creados con el editor clásico y una lista de sus IDs.
- Este código lista solo los posts publicados que no contienen bloques de Gutenberg.
- Excluye páginas, revisiones, posts vacíos, posts sin título y posts sin slug válido.
- Si necesitas incluir otros tipos de contenido (por ejemplo, páginas), cambia `post_type = 'post'` por `post_type IN ('post', 'page')`.
- Si quieres excluir otros tipos de contenido no deseado, agrega más condiciones a la consulta SQL.
And this is what you will get (*in the revision I have added that I also include the figure for the total amount).
Now you can select as many IDs as you want and convert in batches as you wish.
As LucusHost has WP-CLI installed, from cPanel I have the terminal ready to give him cane.
It opens and connects to the root path of your WP installation.
cd public_html/staging
Enter
Finally we type our command with the ID's of the posts we are going to convert. Example:
wp convert-to-blocks start --only=3017,3100,3145,3281,3357,4121,4505,4564,4586,4623,4647,4665,4688,4706,4712,4727,4793,16019,50411,87386
Pressing enter again will give us a url that we will have to open in a new window to start the process.
Converting... Now we just have to wait for it to be finished and take a look at the conversions to see if there is anything to polish and polish up.
There are still a lot of people loyal to the minimalism of the classic editor , but Gutenberg, albeit at a desperately slow pace, has improved a lot since its release. Using it already has more benefits than drawbacks.
Benefits of SEO: Don't expect your site to top the search results list overnight by making this conversion, but every improvement adds up.
Better structure of the content: Gutenberg allows you to create more structured content using blocks (paragraphs, headings, lists, etc.). It makes it easier for search engines to better understand the hierarchy and relevance of content. Optimisation of headings (H1, H2, H3, etc.): It is easier to add and manage headings, improving the readability and organisation of content. More optimised images: Gutenberg allows alt attributes, titles and descriptions to be added directly to image blocks. Use of specific blocks for SEO: If you use plugins like Yoast SEO or Rank Math , they offer specific blocks to improve SEO (e.g. FAQ blocks or Schema Markup). More interactive content: Interactive blocks (tables, buttons, accordions) improve the user experience and reduce bounce rate. Long entries with many elements published with the classic editor tend to have a high CLS and are also slower, so they index worse or lose positioning. Cleaner and lighter code: Gutenberg generates cleaner, more semantic HTML, reducing page size and improving load times. Deferred loading of resources: Some blocks (such as images) allow lazy loading natively. Less reliance on shortcodes: Gutenberg allows many shortcodes to be replaced with more efficient native blocks. Optimisation of visible content (above the fold): It makes it easy to create optimised content for the visible part of the page without scrolling. Fewer plugins needed: Reduce plugin load by integrating functionality such as columns, tables or buttons. Additional benefits:
Better editing experience: It offers a more modern and intuitive editing experience. Compatibility with modern themes and plugins: Many themes and plugins are already optimised for Gutenberg.
Future of the publisher.
Here I'm not so sure. Gutenberg is the (only) future of WordPress, although I think not so much of FSE (Full Site Editing) because not all templates are FSE and many of the most popular templates have not released FSE versions. Also, staff are still using Elementor or Bricks as a builder or GenerateBlocks and/or Kadence, as support blocks.