Home › Forums › General Issues › How to assign random ID to headings (h1,h2,h3,h4 exc) in AFC WYSIWYG field? › Reply To: How to assign random ID to headings (h1,h2,h3,h4 exc) in AFC WYSIWYG field?
Up!
I’ve managed to apply IDs to all WYSIWYG fields, but how could intercept a specific field with its key?
this is the code applied:
function my_heading_ids($content) {
$content = preg_replace_callback(“/\<h([4])/”, function ($matches) {
static $num = 1;
$hTag = $matches[4];
return ‘<h4′. $hTag .’ id=”my’ . $num++ . ‘”‘;
}, $content);
return $content;
}
add_filter(‘acf_the_content’, ‘my_heading_ids’);
Thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.