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


modify html output when add image in posts and pages

我正在尝试编辑帖子中添加图像的输出,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>

我所有的尝试都:(

您需要在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;
       }
?>