是否可以在 WordPress 帖子中注释掉 HTML 代码?

发布于 2024-09-12 00:08:59 字数 246 浏览 5 评论 0原文

有时我需要将一些原始 HTML 代码注入到 Wordpress 帖子中,有时我需要注释掉该代码的一部分。!

使用纯文本编辑器,我可以在我想要隐藏的块周围使用

但是当我在 WP 帖子中尝试此操作时,它确实隐藏了代码,但我仍然看到“结束评论标记”-->

如果可能的话,在 WP 帖子中注释掉代码的正确方法是什么?

谢谢!

Sometimes I need to inject some raw HTML code into a Wordpress post, and sometimes I need to comment out a chunk of that code.!

With a plain text editor, I can just use <!-- Comment --> around the chunk I want to hide.

But when I try this in a WP post, it does hide the code but I still see the "closing comment tag" -->.

What's the right way, if possible, to comment out code in a WP post?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

似最初 2024-09-19 00:08:59

wpaautop() 包含一个错误,该错误会破坏包含 HTML 代码的注释。一个简单的解决方法是在结束之前添加第二个开始 HTML 注释标签 - 这会诱骗 WordPress 按照您的预期工作。请参阅 http://core.trac.wordpress.org/ticket/2691

这会起作用在 WordPress 中:

<!-- <div class="book floatleft"><a href="#">
<img src="http://www.myreallycoolsite.com/wp-content/uploads/2013/02/button.png" alt="" />
</a></div> <!-- -->

这在 WordPress 中不起作用:

<!-- <div class="book floatleft"><a href="#">
<img src="http://www.myreallycoolsite.com/wp-content/uploads/2013/02/button.png" alt="" />
</a></div> -->

wpautop() contains a bug that breaks comments containing HTML code. An easy workaround is to add a second opening HTML comment tag just before the closing - this tricks WordPress into working like you would expect it to. see http://core.trac.wordpress.org/ticket/2691

This will work in WordPress:

<!-- <div class="book floatleft"><a href="#">
<img src="http://www.myreallycoolsite.com/wp-content/uploads/2013/02/button.png" alt="" />
</a></div> <!-- -->

This will not work in WordPress:

<!-- <div class="book floatleft"><a href="#">
<img src="http://www.myreallycoolsite.com/wp-content/uploads/2013/02/button.png" alt="" />
</a></div> -->
薔薇婲 2024-09-19 00:08:59

隐藏 div 块

使用这样的

<div style="display: none;">

...comment...

</div>

:就像魅力一样

Use a hidden div block

like this:

<div style="display: none;">

...comment...

</div>

works like a charm

梦过后 2024-09-19 00:08:59

您可以尝试以下插件之一,它可以在 html 编辑器中保留代码格式:

  • TRUEedit Plugin
  • WP Super Edit
  • ps-disable-auto-formatting
  • 未过滤的 MU(仅限多站点)

我相信这些插件中的大多数都删除了 WordPress 使用的 wptexturize 过滤器,该过滤器替换了字符和模式(这会弄乱一些短代码和 html)。

如果您使用“Deans FCKEditor”或“Foliopress WYSIWYG”,这可能是问题,因为它们将引号转换为 html 引号,添加段落标记,弄乱短代码,并进行其他一些 html 字符替换。

You could try one of the following plugins which preserves code formatting within the html editor:

  • TRUEedit Plugin
  • WP Super Edit
  • ps-disable-auto-formatting
  • Unfiltered MU (multisite only)

I believe most of these plugins removes the wptexturize filter that WordPress uses which replaces characters and patterns (which messes up some shortcodes and html).

If your using 'Deans FCKEditor' or 'Foliopress WYSIWYG' that could be the problem since they convert quotes to html quotes, add paragraph markup, mess up shortcodes, and do some other html character replacement.

居里长安 2024-09-19 00:08:59

这段代码应该能满足您的需求。

// Add the unfiltered_html capability back in to WordPress 3.0 multisite.
function um_unfilter_multisite( $caps, $cap, $user_id, $args ) {
if ( $cap == 'unfiltered_html' ) {
    unset( $caps );
    $caps[] = $cap;
}
return $caps;
}
add_filter( 'map_meta_cap', 'um_unfilter_multisite', 10, 4 );

This snippet should do what you're looking for.

// Add the unfiltered_html capability back in to WordPress 3.0 multisite.
function um_unfilter_multisite( $caps, $cap, $user_id, $args ) {
if ( $cap == 'unfiltered_html' ) {
    unset( $caps );
    $caps[] = $cap;
}
return $caps;
}
add_filter( 'map_meta_cap', 'um_unfilter_multisite', 10, 4 );
尤怨 2024-09-19 00:08:59

试试这个:

<!-- Comment --!>

效果就像一个魅力。

Try this:

<!-- Comment --!>

Works like a charm.

長街聽風 2024-09-19 00:08:59

请确保将评论标签放置在原始 html 编辑器中,而不是在帖子的编辑器中键入

替代文本
(来源:headwaythemes.com

还使用 DOM 检查器来确保 --> 结束标记实际上来自帖子本身。

另一个提示,在发布文章之前,点击关闭标签按钮以确保它更好地验证您的 html。

Instead of typeing <!--Comment--> in the editor for your post, Make sure you place the comment tag inside the raw html editor.

alt text
(source: headwaythemes.com)

Also use a DOM Inspector to make sure that th --> closing tag is actually coming form the post itself.

Another Tip, before you publish the article, hit the Close Tags button to make sure that it validates your html better.

注定孤独终老 2024-09-19 00:08:59

试试这个:

<!--<br />
... commented out stuff ...<br >
<-->

但要注意 WordPress 会在评论末尾添加 HTML 中断标记。

Try this:

<!--<br />
... commented out stuff ...<br >
<-->

but beware the HTML break tag WordPress will throw in at the end of the comment.

回眸一笑 2024-09-19 00:08:59

就像 jharrel 所建议的那样,这工作得很好:

<!-- content <!-- -->

Like jharrel suggested, this works just fine:

<!-- content <!-- -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文