2025年02月15日 建站教程
wordpress获取缩略图的方法有很多,1、特色图片上传,2、自定义字段选择图片litpic;这2种方法是最常用的,但是有很多人觉得麻烦,有很站长想直接从文章中自动截图,下面小编给大家详细介绍一下。
1、打开主题函数模板functions.php,新增以下代码:
function wp_screenshot($atts, $content=null){ extract( shortcode_atts( array( "shots" => "https://www.lmcjl.com/uploads/", "url" => "https://lmcjl.com", "width" => "600", "height" => "450", "alt" => "screenshot" ), $atts ) ); $img = '<div class="wp-shot"><a href="' . $url . '" rel="external nofollow" target="_blank"><img src="/static' . $shots . '' . urlencode($url) . '?w=' . $width . '&h=' . $height . '" alt="' . $alt . '" /></a></div>'; return $img; } add_shortcode("shot", "wp_screenshot");
发表文章时,添加以下标签:
[shot url="https://lmcjl.com/" width="300" height="250"] //width,height可以默认设置也可以自定义
本文链接:http://so.lmcjl.com/news/23208/