Skip to content

Commit

Permalink
Plugin Tweaks: Add a gutenberg tweaks file to fix "level 0" headings
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Feb 27, 2024
1 parent 5adb2e4 commit 7d3d925
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mu-plugins/plugin-tweaks/gutenberg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace WordPressdotorg\MU_Plugins\Plugin_Tweaks\Gutenberg;

defined( 'WPINC' ) || die();

/**
* Actions and filters.
*/
add_filter( 'render_block_core/post-title', __NAMESPACE__ . '\swap_h0_for_paragraph', 20 );
add_filter( 'render_block_core/query-title', __NAMESPACE__ . '\swap_h0_for_paragraph', 20 );

/**
* Replace invalid `h0` tags with paragraphs.
*
* Setting the `level` to 0 technically works for site-title, post-title,
* and query-title, but the latter two don't do any validation before outputting
* `<h{level}>`, so we end up with the invalid `h0` when trying to remove
* heading semantics.
*
* @param string $block_content The block content.
*
* @return string The updated block content.
*/
function swap_h0_for_paragraph( $block_content ) {
return str_replace(
array( '<h0', '</h0>' ),
array( '<p', '</p>' ),
$block_content
);
}

1 change: 1 addition & 0 deletions mu-plugins/plugin-tweaks/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
require_once __DIR__ . '/wporg-internal-notes.php';
require_once __DIR__ . '/stream.php';
require_once __DIR__ . '/incompatible-plugins.php';
require_once __DIR__ . '/gutenberg.php';

0 comments on commit 7d3d925

Please sign in to comment.