{"id":4950779,"date":"2014-05-25T23:18:01","date_gmt":"2014-05-25T23:18:01","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/patch-ignore-empty-tags\/"},"modified":"2016-08-21T20:56:39","modified_gmt":"2016-08-21T20:56:39","slug":"patch-ignore-empty-tags","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/patch-ignore-empty-tags\/","title":{"rendered":"[Patch] Ignore empty  tags"},"content":{"rendered":"<p>Hi,<\/p>\n<p>Sometimes an editor inadvertently creates an empty h tag &#8211; something I&#8217;ve seen countless times in the 10k+ posts on our site so far. I&#8217;ve fixed this in Hackadelic TOC, but now that we&#8217;re switching to TOC Plus, I wanted to have it fixed there too. Here&#8217;s the patch to do so &#8211; it&#8217;d be great if it could be applied to the core (adjust it for white space though, as my editor inserts spaces instead of tabs):<\/p>\n<pre><code>Index: toc.php\n===================================================================\n--- toc.php     (revision 802211)\n+++ toc.php     (working copy)\n@@ -1288,19 +1288,22 @@\n\n                                \/\/ list item\n                                if ( in_array($matches[$i][2], $this-&gt;options[&#039;heading_levels&#039;]) ) {\n-                                       $html .= &#039;&lt;a href=&quot;#&#039; . $this-&gt;url_anchor_target( $matches[$i][0] ) . &#039;&quot;&gt;&#039;;\n-                                       if ( $this-&gt;options[&#039;ordered_list&#039;] ) {\n-                                               \/\/ attach leading numbers when lower in hierarchy\n-                                               $html .= &#039;&lt;span class=&quot;toc_number toc_depth_&#039; . ($current_depth - $numbered_items_min + 1) . &#039;&quot;&gt;&#039;;\n-                                               for ($j = $numbered_items_min; $j &lt; $current_depth; $j++) {\n-                                                       $number = ($numbered_items[$j]) ? $numbered_items[$j] : 0;\n-                                                       $html .= $number . &#039;.&#039;;\n-                                               }\n-\n-                                               $html .= ($numbered_items[$current_depth] + 1) . &#039;&lt;\/span&gt; &#039;;\n-                                               $numbered_items[$current_depth]++;\n-                                       }\n-                                       $html .= strip_tags($matches[$i][0]) . &#039;&lt;\/a&gt;&#039;;\n+          $text = strip_tags($matches[$i][0]);\n+          if (!empty($text)) {\n+                                         $html .= &#039;&lt;a href=&quot;#&#039; . $this-&gt;url_anchor_target( $matches[$i][0] ) . &#039;&quot;&gt;&#039;;\n+                                         if ( $this-&gt;options[&#039;ordered_list&#039;] ) {\n+                                               \/\/ attach leading numbers when lower in hierarchy\n+                                               $html .= &#039;&lt;span class=&quot;toc_number toc_depth_&#039; . ($current_depth - $numbered_items_min + 1) . &#039;&quot;&gt;&#039;;\n+                                               for ($j = $numbered_items_min; $j &lt; $current_depth; $j++) {\n+                                                       $number = ($numbered_items[$j]) ? $numbered_items[$j] : 0;\n+                                                       $html .= $number . &#039;.&#039;;\n+                                               }\n+\n+                                               $html .= ($numbered_items[$current_depth] + 1) . &#039;&lt;\/span&gt; &#039;;\n+                                               $numbered_items[$current_depth]++;\n+                                         }\n+                                         $html .= $text . &#039;&lt;\/a&gt;&#039;;\n+          }\n                                }<\/code><\/pre>\n<p>Before this change: https:\/\/i.imgur.com\/eFXYz5p.png<\/p>\n<p>After the change: https:\/\/i.imgur.com\/JKsLbiK.png<\/p>\n<p>https:\/\/wordpress.org\/plugins\/table-of-contents-plus\/<\/p>\n","protected":false},"template":"","class_list":["post-4950779","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4950779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4950779\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4950779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}