Edit function in WordPress to add id AutoNumber for heading
-
I have a function in wordpress to add id= AutoNumber for heading in content:
function anchor_content_headings($content) { $content = preg_replace_callback("/\<h([1|2|3])\>(.*?)\<\/h([1|2|3])\>/", function ($matches) { $hTag = $matches[1]; $title = $matches[2]; $slug = "" . sanitize_title_with_dashes($title ); return '<a href="#'. $slug .'"><h'. $hTag .' id="' . $slug . '">' . $title . '</h'. $hTag .'></a>'; }, $content); return $content; } add_filter('the_content', 'anchor_content_headings');
The function outputs:
<2 id=#title-test>title test</h2> <2 id=#title-two>title two</h2> <3 id=#title-test-test>title test test</h3>
I want edit function to output:
<2 id=#1>title test </h2> <2 id=#2>title test test </h2> <3 id=#3>title test test </h3>
This mod is because there are problems with non-English languages ??with their use of JavaScript
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Edit function in WordPress to add id AutoNumber for heading’ is closed to new replies.