2013-10-13 19 views
0
使用插入媒体时

我使用WP 3.6.1,当我在插入后添加\编辑屏上的图像会生成像在WordPress的

<a href="..."> 
<img class="alignnone size-medium wp-image-8858" alt="..." src="..." width="300" height="168"/> 
</a> 

但文字如何自动环绕图片标题简码我想要自动生成标题短代码。这里是一个例子:

[caption id="attachment_8858" align="alignnone" width="300"] 
<a href="..."> 
<img class="alignnone size-medium wp-image-8858" alt="..." src="..." width="300" height="168"/> 
</a>Caption text 
[/caption] 

它是如何实现的?我知道一些主题\插件允许,但我找不到这样的。

在此先感谢

回答

0

您可以使用筛选器挂钩image_send_to_editor。它允许操纵正在插入的HTML。

<?php 
/** 
* Plugin Name: Add Caption to Inserted Images 
*/ 

add_filter('image_send_to_editor', 'b5f_image_to_editor', 10, 8); 
function b5f_image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) 
{ 
    // Manipulate the HTML 
    return $html; 
} 

的值被传递在一个简单的测试:

[html]  => <a href="http://example.dev/wp-content/uploads/image.png"><img src="http://example.dev/wp-content/uploads/image.png" alt="alternate text" width="128" height="128" class="alignnone size-full wp-image-176" /></a> 
[id]  => 176 
[caption] => 
[title]  => 
[align]  => none 
[url]  => http://example.dev/wp-content/uploads/image.png 
[size]  => full 
[alt]  => alternate text