0
<div class="form-container">

    <div class="form-field">
        <label>
            <input id="woo-bookings-enabled" type="checkbox" name="woo-bookings-enabled" value="1">Enable bookings
        </label>
    </div>

    <div class="form-field hide-if-bookings-disabled" style="display: block;">
        <label>
            Length:  <input type="number" name="..." value="1">
            <select>
                    <option>...</option>
                    <option>...</option>
            </select>
        </label>
    </div>


    <div class="form-field hide-if-bookings-disabled">
        <label>Cost: <input type="number" name="session-cost" value="0" min="0" step="0.01">
        </label>
    </div>


    <div class="form-field hide-if-bookings-disabled">
        <label>
            <input type="checkbox" name="customer-timezone" value="on">Use the customer's timezone
        </label>
    </div>

</div>

Now I'd like to add an extra html code <span class="form-field-checkbox"></span> to input["type=checkbox"] only.

My function is like this but it doesn't work as I hoped it would.

function theme_form_checkbox($output) {
    $search  = array('<div class="form-field"><label><input .*?checkbox.*?>','</label>');
    $replace = array('<div class="form-field"><label><input .*?checkbox.*?>', '<span class="form-field-checkbox"></span></label>'); 

    return str_replace( $search, $replace, $output );
}   
add_filter( 'the_content', 'theme_form_checkbox', 99, 1 );

Any help is much appreciated

  • Use preg_replace() in case you want to use regular expressions. – Max Yudin Feb 21 '17 at 11:39
  • Could you give an example? I have some dificulties with the expressions. – kiarashi Feb 21 '17 at 12:32
0

I looked at this from a far difficult angle, while the answer was so simple. For anyone in a similar situation:

$('<span class="form-field-checkbox"></span>').insertAfter('input:checkbox,input:radio');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.