Support

Account

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