下面由WordPress教程欄目給大家介紹如何在 wordpress 文章中自動(dòng)獲取網(wǎng)站截圖,希望對(duì)需要的朋友有所幫助!
一、短代碼
將下面的代碼添加到當(dāng)前主題函數(shù)模板 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><a>@@##@@</a></div>'; return?$img; } add_shortcode("shot",?"wp_screenshot");
發(fā)表文章時(shí),添加短代碼:
[shot?url="http://zmingcx.com/"]
或者自定義截圖大小
[shot?url="http://zmingcx.com/"?width="600"?height="450"]
修改其中的網(wǎng)址鏈接鏈接即可。
具體效果
二、直接添加鏈接
這個(gè)方法使用更加方便,獲取截圖的基本格式:
https://s0.wordpress.com/mshots/v1/http://zmingcx.com/?w=600&h=450
也可以直接將上述地址鏈接格式像正常插入圖片(從URL插入)一樣添加到文章中,上面的截圖就是這么加的,并沒(méi)有用短代碼。
因需要即時(shí)生成截圖,第一次打開(kāi)可能看不到圖片,刷新一下就可以了,不行就多刷新幾次。生成的截圖存儲(chǔ)在WordPress.com服務(wù)器上,不會(huì)占用自己的空間和資源,不過(guò)加載可能有些慢。
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END