Php 如何在wordpress插件开发中删除图像中的锚定标签?
在此图像中,黑点是背景图像上的另一个图像。我能把那个黑点嵌入到那张帖子的图片上Php 如何在wordpress插件开发中删除图像中的锚定标签?,php,anchor,wordpress,Php,Anchor,Wordpress,在此图像中,黑点是背景图像上的另一个图像。我能把那个黑点嵌入到那张帖子的图片上 $embedCode ='div id="mainCHImage"style="position:relative;height:'.$heightOrg.'px;width:'.$widthOrg.'px;">'. '<img style="background:none;border:none;height:'.$heightOrg.'px !important;
$embedCode ='div id="mainCHImage"style="position:relative;height:'.$heightOrg.'px;width:'.$widthOrg.'px;">'.
'<img style="background:none;border:none;height:'.$heightOrg.'px !important;width:'.$widthOrg.'px !important;"'. "src=\"{$matches[1]}\";>".'
</div>
<img id="Icon" style="position:relative;left:'.$imgWidth.'px;top: '.$imgHeight.'px;padding-left: 10px;z-index:9999;cursor:pointer;background:none;border:none;" src="/Icon.png" onClick="showProducts(event,'."'{$matches[1]}'".')"></div>
$embedCode='div id=“mainCHImage”style=“位置:相对;高度:'.$heightOrg.px;宽度:'.$widthOrg.px;”>”。
'".'
这是我用来替换post图像的代码,以便在背景图像上显示那个黑点。
现在的问题是点击黑点,我想运行一个javascript函数,但在wordpress中,它被包装在带有背景图像href的锚标记下,因此没有得到点击事件。但是我已经禁用了图像上的链接,然后它工作了,但不是正确的方式。下面我粘贴了这段代码的inspect元素响应
<a href="http://localhost/wordpress/wp-content/uploads/2013/04/9.jpg">
<img id="Icon" style="position:relative;left:130px;top: -30px;padding-left: 10px;z-index:9999;cursor:pointer;background:none;border:none;"
src="/Icon.png" onclick="showProducts(event,'http://localhost/wordpress/wp-content/uploads/2013/04/9.jpg')">
我不知道锚定标记来自何处..我的代码中没有添加..add\u filter('the\u content'、'attachment\u image\u link\u remove\u filter');
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
$content =preg_replace(array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}','{ wp-image-[0-9]*" /></a>}'),array('<img', '" />'), $content);
return $content;
}
/*place this code in your functions.php*/
/*if you wanna remove anchor tags which has image links, follow below code*/
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
global $post;
$exceptional_cjtypes = array("Mashup");
$cjtype = wp_get_post_terms($post->ID, "cjtype");
if(!in_array(strtolower($cjtype[0]->name), array_map('strtolower', $exceptional_cjtypes))) {
$content =preg_replace(
array('{<a href="(.*?(gif|jpeg|jpg|png))"><img}',
'{ wp-image-[0-9]*" /></a>}'),
array('<img', '" />'),
$content
);
}
return $content;
}
函数附件\图像\链接\删除\过滤器($content){
$content=preg_replace(数组({}'),
排列(“你是如何获取/获取图像的?你只是硬编码吗?目前我正在进行编码…你说它会在img标记上方自动预加一个锚定标记?这段代码在哪里?是的..你说对了..我必须尝试并用diff div编写,但徒劳无功..我认为它的wordpress属性或类似于tat的东西..我正在本地主机上工作..所以我可以这样做t show u live.请编辑你的答案,将你的评论放在答案正文中。这样会更干净。