2016-01-19 57 views
2

我已經搜索了高和低的解決方案。我想從這個在WordPress改變上傳圖像的標記:如何自定義插入WordPress文章的圖像的HTML標記?

<div id="attachment_906" style="width: 590px" class="wp-caption aligncenter"> 
    <img class="size-full wp-image-906 " title="Image Alignment 580x300" alt="Image Alignment 580x300" src="http://localhost/sandbox/wp-content/uploads/2013/03/image-alignment-580x300.jpg" width="580" height="300"> 
    <p class="wp-caption-text">Look at 580×300 getting some <a title="Image Settings" href="http://en.support.wordpress.com/images/image-settings/">caption</a> love.</p> 
</div> 

要更多的東西是這樣的:

<figure class="center"> 
    <img class="gallery-img" src="http://lorempixel.com/300/500/"> 
    <figcaption> 
     <span>A slightly longer caption for the image, which is significantly smaller than the last one. pretty neat!</span> 
    </figcaption> 
</figure> 

據我所知,很多在原崗位的標記都需要留下來,但有沒有什麼辦法可以自定義的任何這個?即使我可以獲得相同的基本結構(包裝器,圖像,標題包裝器,標題),我也可以從CSS中獲取它。

由於我正在開發一個主題,我需要使用本地WordPress工具的選項。如果情況並非如此,我無法使用它。

我本來希望只要有一個過濾器或行動,我可以申請這樣做,但我沒有找到這樣的事情運氣。

提前致謝!

+1

這些圖像已通過編輯器添加到'the_content'嗎? – rnevius

+0

這是正確的 –

回答

1

您需要使用image_send_to_editor過濾器。 https://developer.wordpress.org/reference/hooks/image_send_to_editor/

在任何一個活動主題或插件的php文件(如functions.php)中,這可能看起來像這樣:

function filter_image_send_to_editor($content) { 
    $content .= '<figure class="center">(Generate your markup here)</figure>'; 

    return $content; 
} 
add_filter('image_send_to_editor', 'filter_image_send_to_editor'); 

當然,您必須在該函數內編寫自己的代碼。

相關問題