我正在努力实现JAIL javascript 安装到我的WordPress中。javascript要求我添加一个数据属性并更改图像的输出html。
我一直在看法典,寻找可以帮助我的过滤器或挂钩,但我什么也找不到。有人有办法吗?
我正在努力实现JAIL javascript 安装到我的WordPress中。javascript要求我添加一个数据属性并更改图像的输出html。
我一直在看法典,寻找可以帮助我的过滤器或挂钩,但我什么也找不到。有人有办法吗?
在将自定义图像数据插入帖子时,最好使用media_send_to_editor
, 需要注意的是,这不会应用于任何现有图像,只会应用于添加功能后插入的图像。
要将其应用于现有内容,您将使用preg_match
在…上the_content
过滤,但这会显著降低站点速度,建议您不要像这样解析输出。
A.media_send_to_editor
示例:
function WPSE_78285_Mime($html, $id) {
//fetching attachment by post $id
$attachment = get_post($id);
$mime_type = $attachment->post_mime_type;
//get an valid array of images types
$image_exts = array( \'image/jpg\', \'image/jpeg\', \'image/jpe\', \'image/gif\', \'image/png\' );
//checking the above mime-type
if (in_array($mime_type, $image_exts)) {
// the image link would be great
$src = wp_get_attachment_url( $id );
// enter you custom output here, you will want to probably change this
$html = \'<a href="\' . $src . \'" class="your-class" data-src="/img/image1.jpg" rel="your-rel"><img src="\'. $src .\'" /></a>\';
return $html; // return new $html
}
return $html;
}
add_filter(\'media_send_to_editor\', \'WPSE_78285_Mime\', 20, 2);
有没有办法不使用get\\u the\\u extract()获取图像?我正在使用my\\u recent\\u post()函数将帖子拉到主页上,我不需要让它拉帖子中的图像,只需拉一些文本。下面是我正在使用的函数:function my_recent_post() { global $post; $html = \"\"; $my_query = new WP_Query( array( \'post_type\' => \'po