从 the_content WordPress 中删除带有 ID 的 div

阿卜杜勒·瓦希德 |

我试图从 the_content WordPress 中删除具有某些 ID 的 div。我正在努力实现这样的目标

jQuery( "#some_id" ).remove();

但在服务器端,

我不知道如何在 the_content 过滤器挂钩中的服务器端执行此操作。

这是我喜欢实现的目标,

add_filter( 'the_content', 'my_the_content_filter', 20 );
function my_the_content_filter( $content ) {


    $content.find('#some_id').remove();


    return $content;
}
乔尔·斯塔德尔

我认为这是您问题的答案:https : //stackoverflow.com/a/1114925/7335278

在您的情况下,这看起来像:

add_filter( 'the_content', 'my_the_content_filter', 20 );
function my_the_content_filter( $content ) {


    $doc = new DOMDocument();
    $doc->loadHTML($content);
    $element = $doc->getElementById('some_id');
    $element->parentNode->removeChild($element);
    $content = $doc->saveHTML();


    return $content;
}

hth,让我们知道这是否有效。干杯,乔尔

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

wordpress the_content()未在正确的div中显示

需要从the_content()获取所有<img>;在WordPress中?

了解wordpress the_content

有条件的“ the_content”过滤器wordpress

从 WordPress 中的“the_content”功能中剪切文本

在 WordPress 中 the_content() 前后添加内联图标

如何在the_content();中将图像包装在div中?

通过ID获取the_content并在WordPress中保留<p> -tag

the_content()在div外部显示

从数据库 wordpress 中删除带有 id 的图像

带有div标签id的wordpress jQuery分页

WordPress的the_content(); 显示内容和附件

wordpress-如果bbpress显示the_content()

在wordpress插件上使用the_content钩子

WordPress:get_the_content()和the_content()之间的区别

从一个页面获取the_content并在另一页面中显示(Wordpress)

WordPress apply_filters( 'the_content', 'func_name' ) 在另一个钩子中不起作用

Wordpress the_content()输出文档类型声明

如何在WordPress中分离帖子的the_content

WordPress 将 php 代码运行到 the_content 循环中

尝试从the_content中删除三个或更多<br>

获取wordpress中带有数组的帖子ID

从the_content删除一些html标签

jquery删除(div)中的id

在 CSS 中 ID 末尾带有奇数/偶数的目标 div

如何使用 Greasemonkey 修改带有 id 的 div 中的标签

将the_content()存储到javascript / jquery变量中

特殊字符移到the_content中的行首

WordPress:front-page.php上的the_content过滤器