在制作博客时,可以使用如下代码可以快速截取网站截图缩短时间
代码如下(代码插入 主题里面的functions.php 中)
function wp_screenshot($atts, $content=null){
extract(
shortcode_atts(
array(
"shots" => "https://s0.wordpress.com/mshots/v1/",
"url" => "https://www.wpbeginner.com",
"width" => "600",
"height" => "450",
"alt" => "screenshot"
),
$atts
)
);
$img = '<div class="wp-shot"><a href="' . $url . '" rel="external nofollow noopener noreferrer" target="_blank"><img src="' . $shots . '' . urlencode($url) . '?w=' . $width . '&h=' . $height . '" alt="' . $alt . '" /></a></div>';
return $img;
}
add_shortcode("shot", "wp_screenshot");
在我们需要发布文章时后,可以添加短代码:
[shot url="网站域名"]
还可以实现自定义截图大小
[shot url="网站域名" width="600" height="450"]
提醒一下:由于系统是实时生成截图,所以第一次打开时可能看不到图片,刷新一下,如果没用则刷新几次。 生成的屏幕截图存储在 WordPress.com 服务器上,不会占用自己的空间,不过加载可能有些慢。
此文转自https://ucyclub.com/thread-292-1-1.html