I'm trying to add html markup to an unordered list with a specific class.
This would be the HTML to start with:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ul class="foo">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
And I would like to end up with:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ul class="foo">
<li><svg class="icon"><use xlink:href="#foo"></use></svg>Item 1</li>
<li><svg class="icon"><use xlink:href="#foo"></use></svg>Item 2</li>
<li><svg class="icon"><use xlink:href="#foo"></use></svg>Item 3</li>
</ul>
I haven't found a regex that could be used to run a preg_replace() that can get this to work.
The content is created with Wordpress. I want to use a filter that scans the_content and adds the extra markup. In such a manner:
function foo_ul($text) {
//some function
return $text;
}
add_filter('the_content', 'foo_ul');
I do not want to be reliant on Javascript/jQuery so I would like this to be generated on the server-side.
Any ideas?