在帖子和页面中添加图像时修改html输出

时间:2013-11-03 20:24:51

标签: php wordpress wordpress-theming

我正在尝试在帖子中编辑添加图片的输出,而wordpress的正常代码是

<a href="http://huemix.ly/wp-content/pics/pic.jpg"><img src="http://huemix.ly/wp-content/pics/pic.jpg" /></a>

我想用

替换该输出
<div class="huemix">
    <img class="posts-img" src="http://huemix.ly/wp-content/pics/pic.jpg" />
    <a href="http://huemix.ly/wp-content/pics/pic.jpg" class="fancybox" ></a>
    <div class="fancy"></div>
</div>

我的所有尝试都会失败:(

1 个答案:

答案 0 :(得分:2)

您需要在wordpress函数文件中搜索适当的代码块。该文件应命名为post.php,并且应位于wp-includes。函数名称应为wp_insert_attachment()

或使用过滤器:

<?php 
       add_filter( 'image_send_to_editor', 'my_image_func', 10, 7);
       function my_image_func($html, $id, $alt, $title, $align, $url, $size ) {
           $url = wp_get_attachment_url($id); // Grab the current image URL
           $html = "<img src="$url" class="uhuhu"/>";
           return $html;
       }
?>