function video_shortcode($atts) { // Attribute extrahieren $atts = shortcode_atts( array( 'src' => '', // Video-URL 'width' => '600', // Standardbreite 'height' => '400' // Standardhöhe ), $atts, 'video' ); // Video-Tag erstellen $output = '<video width="' . esc_attr($atts['width']) . '" height="' . esc_attr($atts['height']) . '" controls>'; $output .= '<source src="' . esc_url($atts['src']) . '" type="video/mp4">'; // type nach Bedarf anpassen $output .= 'Dein Browser unterstützt das Video-Tag nicht.'; $output .= '</video>'; return $output; } add_shortcode('video', 'video_shortcode');
After you enter this code into the functions.php
you can use the shortcode [video]
in your posts, pages or widgets, and with the attributes src
, width
and height
For example:
[video src="URL_DES_VIDEOS" width="800" height="450"]
Do not forget, URL_OF_VIDEO
with the actual URL of your video.
Please make sure you use a child theme or create a custom plugin to add the code so that your changes are not lost when you update the theme.