-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Youtube Iframe filter dont work at custom field #2804
Comments
Until #2202 gets implemented, which would automatically convert the I'm sure @westonruter knows how to best do this in an automated way using the existing sanitizers. |
@westonruter please tell me how to be =) |
@majestica Are you using Advanced custom fields? As you are using AMP in Reader mode you could do the following, which will result in the videos playing in AMP only (and if the video field is left blank the featured image will appear in its place).
That worked for me anyway, although I am sure Weston might have a better solution |
@jamesozzie There's a better way to do this in a way that doesn't result in duplicate scripts. Namely: add_filter(
'amp_post_template_data',
function( $data ) {
$data['amp_component_scripts'] = array_merge(
$data['amp_component_scripts'],
array(
'amp-youtube' => true,
)
);
return $data;
}
); |
@jamesozzie Thanks, "Are you using Advanced custom fields?" No, i use wordpress default meta field, and i have more thank 5000 post with full iframe link, i cant use only video ID((( |
@westonruter I need your advice if it possible |
So what is the contents of an example |
Yes, for example in postmeta _mvp_video_embed when I use everything inside the context, it works fine, the problem is only with the post-meta, it does not convert these i-frames into the amp format |
@majestica The best way to do this would be to prepend your content with the meta. Try this: add_filter(
'the_content',
function( $content ) {
$meta = get_post_meta( get_the_ID(), '_mvp_video_embed', true );
if ( $meta && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && ! current_theme_supports( 'amp' ) ) {
$content = "$meta\n\n$content";
}
return $content;
},
0
); This will prepend the |
@westonruter I found this in official docs
|
Sure, you can just inject the add_filter(
'the_content',
function( $content ) {
$meta = get_post_meta( get_the_ID(), '_mvp_video_embed', true );
if ( $meta && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && ! current_theme_supports( 'amp' ) ) {
$meta = str_replace( '<iframe', '<iframe layout=responsive ', $meta );
$content = "$meta\n\n$content";
}
return $content;
},
0
); However, it is better if you would use an add_filter(
'the_content',
function( $content ) {
$meta = get_post_meta( get_the_ID(), '_mvp_video_embed', true );
if ( $meta && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && ! current_theme_supports( 'amp' ) && preg_match( '#<iframe.+?https://www\.youtube\.com/embed/([a-zA-Z0-9_-]+)#si', $meta, $matches ) ) {
$videoid = $matches[1];
$url = "https://www.youtube.com/watch?v=$videoid";
$content = "$url\n\n$content";
}
return $content;
},
0
); This will also be responsive. |
Hi, please tell me, I encountered such a problem:
I keep in my custom field links to YouTube in the format
<iframe width = "1226" height = "480" src = "https://www.youtube.com/embed/nBpNfZkWurQ" frameborder = "0" allow = "autoplay ; encrypted-media "allowfullscreen> </ iframe>
In the normal version of the post, if the custom field with the video is filled instead of the picture, I’m showing the video (for example URL , in the amp version before the video was not shown, then the google console started sending errors that the content in the normal version and amp is different, after which I slightly changed the template output amp version to
Result URL
But now the problem is that Google sends errors that they say YouTube does not match the amp format, please tell me, can I do something?
P.S
Ideally, of course, I would like to see in the amp version, if the custom video field is filled show iframe instead of a featured image as it happens in the regular post, but unfortunately I haven’t really figured out how to do it, I will be grateful for any help
The text was updated successfully, but these errors were encountered: