我正在使用WP 3.6.1,当我在post add \ edit屏幕中插入图像时,会生成类似
的文本<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 :(得分: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