<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>
现在我想添加一个额外的html代码
<span class="form-field-checkbox"></span>
到
input["type=checkbox"]
只有
我的函数是这样的,但它并没有像我希望的那样工作。
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 );
非常感谢您的帮助
最合适的回答,由SO网友:kiarashi 整理而成
我从一个非常困难的角度来看这个问题,而答案很简单。对于处于类似情况的任何人:
$(\'<span class="form-field-checkbox"></span>\').insertAfter(\'input:checkbox,input:radio\');