Add span to heading block

<?php

/**
 * Heading block, line style
 *
 */
function be_heading_line_style( $content, $block ) {

	if( 'core/heading' === $block['blockName' ] && !empty( $block['attrs'] ) && !empty( $block['attrs']['className'] ) ) {
		$classes = explode( ' ', $block['attrs']['className'] );
		if( in_array( 'is-style-line', $classes ) ) {
			$content = be_inner_span( $content );
		}
	}

	return $content;
}
add_filter( 'render_block', 'be_heading_line_style', 10, 2 );

/**
 * Inner Span
 *
 */
function be_inner_span( $content = '' ) {
	$start = '">';
	$start_pos = strpos( $content, $start );
	$end = '</';
	$end_pos = strrpos( $content, $end );

	if( false !== $start_pos ) {
		$content = substr_replace( $content, '</span>' . $end, $end_pos, strlen( $end ) );
		$content = substr_replace( $content, $start . '<span>', $start_pos, strlen( $start ) );
	}

	return $content;
}
Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk