下面由wordpress教程栏目给大家介绍如何在 wordpress 文章中自动获取网站截图,希望对需要的朋友有所帮助!
一、短代码
将下面的代码添加到当前主题函数模板 functions.php 中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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><a>@@##@@</a></div>;
return $img;
}
add_shortcode("shot", "wp_screenshot");
发表文章时,添加短代码:
1
[shot url="http://zmingcx.com/"]
或者自定义截图大小
1
[shot url="http://zmingcx.com/" width="600" height="450"]
修改其中的网址链接链接即可。
具体效果
二、直接添加链接
这个方法使用更加方便,获取截图的基本格式:
1
https://s0.wordpress.com/mshots/v1/http://zmingcx.com/?w=600&h=450
也可以直接将上述地址链接格式像正常插入图片(从URL插入)一样添加到文章中,上面的截图就是这么加的,并没有用短代码。

以上就是在 WordPress 文章中自动获取网站截图的详细内容,更多请关注php中文网其它相关文章!