admin管理员组文章数量:1432001
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');
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');
Share Improve this question edited Feb 23, 2020 at 0:05 Ersin asked Feb 22, 2020 at 19:21 ErsinErsin 31 silver badge3 bronze badges 5 |1 Answer
Reset to default 0I've added some comments to clarify a problem with your code:
function swvideo( $html) {
if ( $html ) { // if $html == true
return $html;
}
$post = get_post( $post ); // irrelevant
if ( ! $html ) { // if $html != true
return $html;
}
...
As you can see, nothing past this point will be executed, because the input $html must either be equivalent to true, or not equivalent to true.
I can't tell clearly what you're trying to accomplish, but maybe advanced custom fields would help?
本文标签: videoembedhtml block usage out of thecontent
版权声明:本文标题:Video, embed, html block usage out of the_content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744722102a2621754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
html
defined? did you mean to check$content
? – Michael Commented Feb 22, 2020 at 21:31$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. – Michael Commented Feb 22, 2020 at 23:46function 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'); – Ersin Commented Feb 23, 2020 at 0:02