- This topic has 3 replies, 2 voices, and was last updated 3 years, 8 months ago by
David.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
September 15, 2022 at 7:09 am #2343723
Jens
I have a custom post type “News” that contains three custom fields (video_id, video_start, video_end). These are used to display video snippets. This can be done with a hook and the attached code.
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper"> <iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" type="text/html" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/<?php echo get_post_meta( get_the_ID(), 'video_id', true ); ?>?autoplay=1&fs=0&controls=0&iv_load_policy=3&showinfo=0&rel=0&cc_load_policy=0&start=<?php echo get_post_meta( get_the_ID(), 'video_start', true ); ?>&end=<?php echo get_post_meta( get_the_ID(), 'video_ende', true ); ?>"></iframe></div></figure>How can I achieve the same with a custom shortcode [video_block_cpt_news] ? I need this shortcode to use with GenerateBlocks.
Thank you for your suggestions.
September 15, 2022 at 8:56 am #2343987David
StaffCustomer SupportHi there,
this doc explains creating a shortcode that uses object buffering:
https://docs.generatepress.com/article/creating-a-shortcode/
For your needs you should be able to do this:
add_shortcode( 'video_block_cpt_news', function() { ob_start(); ?> <figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"> <div class="wp-block-embed__wrapper"> <iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" type="text/html" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/<?php echo get_post_meta( get_the_ID(), 'video_id', true ); ?>?autoplay=1&fs=0&controls=0&iv_load_policy=3&showinfo=0&rel=0&cc_load_policy=0&start=<?php echo get_post_meta( get_the_ID(), 'video_start', true ); ?>&end=<?php echo get_post_meta( get_the_ID(), 'video_ende', true ); ?>"></iframe> </div> </figure> <?php return ob_get_clean(); } );September 15, 2022 at 10:31 am #2344071Jens
Thank you very much. Great support.
September 16, 2022 at 3:08 am #2344609David
StaffCustomer SupportYou’re welcome
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.