I have tried hundreds ways but i couldn't do yet. I am beginner, please someone help me !
When admin use for add/upload/embed video any 3 of these blocks; video, core-embed and html i will show the output without use the_content.
function swvideo( $html) {
if ( $html ) {
return $html;
}
$post = get_post( $post );
if ( ! $html ) {
return $html;
}
if ( ! function_exists( 'has_blocks' ) ) {
return $html;
}
if ( ! has_blocks( $post->post_content ) ) {
return $html;
}
$pattern = "/<!--\ wp:html.*-->([\s\S]*?)<!--\ \/wp:html -->/i";
preg_match_all( $pattern, $post->post_content, $html );
if ( ! empty( $html[1] ) ) {
$html = reset( $html[1] );
}
return $html;
}
add_filter( 'the_content', 'swvideo');
html
defined? did you mean to check$content
?$content
. the variable$html
is not known or defined in your filter function. try and change the code tofunction swvideo( $html)
and see what happens.function swvideo( $html) { if ( $html ) { return $html; } $post = get_post( $post ); if ( ! $html ) { return $html; } if ( ! function_exists( 'has_blocks' ) ) { return $html; } if ( ! has_blocks( $post->post_content ) ) { return $html; } $pattern = "/<!--\ wp:html.*-->([\s\S]*?)<!--\ \/wp:html -->/i"; preg_match_all( $pattern, $post->post_content, $html ); if ( ! empty( $html[1] ) ) { $html = reset( $html[1] ); } return $html; }
add_filter( 'the_content', 'swvideo');