简体   繁体   English

Wordpress 自动关闭<a>标签</a>

[英]Wordpress auto closing <a> tags

I've run in to this annoying feature of Wordpress before, but mainly with it obsessively <p> tagging everything, this is a little different.我之前遇到过 Wordpress 的这个烦人的功能,但主要是因为它痴迷于 <p> 标记所有内容,这有点不同。 I've got a bit of php in my themes functions file which loads and parses content from a series of blog posts, grabbing data like links, images and the text and reformatting it... I'm building a client website and trying to make it easy for them to display some offers on the front page, they just need to dump a relevant image, link and a few lines of text in to a blog post and it'll be read and outputted by this code.我的主题函数文件中有一些 php,它加载和解析一系列博客文章中的内容,获取链接、图像和文本等数据并重新格式化......我正在构建一个客户端网站并尝试使他们可以轻松地在首页上显示一些优惠,他们只需将相关图像、链接和几行文本转储到博客文章中,这些代码就会被读取和输出。

I understand Wordpress doesn't like you wrapping block level elements in <a> tags, which would usually be easily avoidable, except the the text is within <h2> tags which are set to block, so if I try to link them Wordpress removes my </a> tag and inserts its own right after the <a>, leaving an empty link.我了解 Wordpress 不喜欢您将块级元素包装在 <a> 标记中,这通常很容易避免,除了文本位于设置为阻止的 <h2> 标记内,所以如果我尝试链接它们,Wordpress 会删除我的 </a> 标签并在 <a> 之后插入自己的标签,留下一个空链接。

ie, I'm expecting (and generating in my php) output like:即,我期待(并在我的 php 中生成)输出,如:

<a href="some_url"><h2>Here's my text</h2></a>

...and Wordpress is changing it to: ...而 Wordpress 将其更改为:

<a href="some_url"></a><h2>Here's my text</h2>

I don't want to disable error checking etc globally since this is for non-tech savvy clients and they'll probably need that, so is there a way to disable this on a page-by-page basis - or even better, disable it on a specific section of HTML?我不想在全球范围内禁用错误检查等,因为这是针对非技术精通的客户,他们可能需要,所以有没有办法逐页禁用它 - 或者更好的是,禁用它在 HTML 的特定部分?

Thanks for any advice!感谢您的任何建议!

This is not related to wordpress,this is HTML specification : This answer is from this Question :这与 wordpress 无关,这是 HTML 规范:这个答案来自这个问题

You can only place <h2> elements within <a> elements if you're working with HTML5, which allows any other elements within <a> elements.如果您使用的是 HTML5,则只能将<h2>元素放置在<a>元素中,这允许在<a>元素中放置任何其他元素。 Previous specifications (or current ones however you want to look at them) never allowed this.以前的规范(或当前的规范,但是您想查看它们)从未允许这样做。

The usual way of doing this is to place <a> within <h2> .这样做的常用方法是将<a>放在<h2>中。 This works, has always worked, and has been the only valid way to do it before HTML5, for heading links, as the link refers to the text in that heading.这有效,一直有效,并且一直是 HTML5 之前唯一有效的方法,用于标题链接,因为链接指的是该标题中的文本。 You rarely need to place <h2> within <a> unless that <h2> is part of some more complex structure which functions as a hyperlink as a whole.你很少需要将<h2>放在<a>中,除非<h2>是一些更复杂的结构的一部分,它作为一个整体用作超链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM