-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin Tweaks: Add a gutenberg tweaks file to fix "level 0" headings
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters