如何在 Wordpress 上检测基于设备的 HTML 代码?
How to detect HTML code based on device on Wordpress?
我没有经验 HTML 并试图在 WordPress 上为自己制作一个小网站。
我有以下自定义代码可以在我的网站上播放视频:
<video poster="video poster link" controls="controls" width="270" height="490">
<source src="video link" type="video/mp4"></video>
视频播放器在桌面站点中完美显示。但是,当 WordPress 为平板电脑调整网站大小时,它确实会拉伸很多。因此,我想在 tablets/mobile 设备上显示时更改代码中的大小。
为了检测,我在网上找到了以下代码,但我无法让它工作:
<?php
if ( wp_is_mobile() ) {
/* Include/display resources targeted to phones/tablets here */
} else {
/* Include/display resources targeted to laptops/desktops here */
}
?>
谢谢。
如果您没有编辑 wordpress 网站代码的权限,您可以添加一个插件,例如 fitvids。
如果你有编辑权限,你可以添加一个媒体查询来检查设备宽度是否像这样
@media screen and (max-width: 768px) {
video {
max-width: 75%;
height:auto;
} // iPad
@media screen and (max-width: 480px) {
video {
max-width: 45%;
height:auto;
} //Phone
根据需要调整宽度..
希望对您有所帮助
我没有经验 HTML 并试图在 WordPress 上为自己制作一个小网站。
我有以下自定义代码可以在我的网站上播放视频:
<video poster="video poster link" controls="controls" width="270" height="490">
<source src="video link" type="video/mp4"></video>
视频播放器在桌面站点中完美显示。但是,当 WordPress 为平板电脑调整网站大小时,它确实会拉伸很多。因此,我想在 tablets/mobile 设备上显示时更改代码中的大小。
为了检测,我在网上找到了以下代码,但我无法让它工作:
<?php
if ( wp_is_mobile() ) {
/* Include/display resources targeted to phones/tablets here */
} else {
/* Include/display resources targeted to laptops/desktops here */
}
?>
谢谢。
如果您没有编辑 wordpress 网站代码的权限,您可以添加一个插件,例如 fitvids。 如果你有编辑权限,你可以添加一个媒体查询来检查设备宽度是否像这样
@media screen and (max-width: 768px) {
video {
max-width: 75%;
height:auto;
} // iPad
@media screen and (max-width: 480px) {
video {
max-width: 45%;
height:auto;
} //Phone
根据需要调整宽度..
希望对您有所帮助