Home >CMS Tutorial >WordPress >Detailed explanation of how to use WordPress's own short code to add videos

Detailed explanation of how to use WordPress's own short code to add videos

藏色散人
藏色散人forward
2021-04-09 11:46:383667browse

The following tutorial column of WordPress will introduce to you how to add videos using the short code that comes with WordPress. I hope it will be helpful to friends in need!

Detailed explanation of how to use WordPress's own short code to add videos

Use WordPress’s built-in short code to add videos

Using WordPress’s built-in video short code allows you to easily add videos anywhere Location to add videos, supported file types are mp4, m4v, webm, ogv, wmv and flv.

Detailed explanation of how to use WordPresss own short code to add videos

Basic video short code

【video src="pepper.mp4"】

Replace [] with [], the following same

will be automatically called when added to the article WordPress comes with a player.

Using shortcodes in template files

You can use the do_shortcode() function to call the video in the theme template. If the video file is stored in your theme directory, use get_template_directory_uri() or get_stylesheet_uri() Get the file url directly.

$video_file = get_template_directory_uri() . "/videos/pepper.mp4";
echo do_shortcode('【video mp4=' . $video_file . '】');

Looping and automatic playback

Looping and automatic playback can be achieved through parameters, and the class is defined as my-video

echo do_shortcode('【video mp4=' . $video_file . ' loop = "on" autoplay = 1 class = my-video】');

Add video cover (placement image)

If you use the cover.jpg picture in the (theme directory)/images folder as the cover:

echo do_shortcode('【video mp4=' . $video_file . ' poster = ' . get_template_directory_uri() . '/images/cover.jpg】');

Set the video height and width

echo do_shortcode('【video mp4=' . $video_file . ' width = 320 height = 240】');

More

The above is the detailed content of Detailed explanation of how to use WordPress's own short code to add videos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete