对于我的自定义设置字段,我希望插入它right after the Site Address (URL) field 在常规设置页面中。
我可以使用add_settings_field()
. 默认情况下,它会添加自定义字段at the bottom. 使用jQuery,我可以在网站地址(URL)后显示我的自定义字段:
add_action( \'admin_footer\', \'wpse_243810_admin_footer\' );
function wpse_243810_admin_footer() {
?>
<script type="text/javascript">
jQuery(\'#protocol_relative\').closest(\'tr\').insertAfter(\'#home-description\').closest(\'tr\');
</script>
<?php
}
但是,它看起来如下所示:查看代码,它会在Site Address字段的<tr>
要素我怎么能把它插到外面呢?下面是每个字段的单独代码段。
<tr>
<th scope="row"><label for="home">Site Address (URL)</label></th>
<td>
<input name="home" type="url" id="home" aria-describedby="home-description" value="http://example.com" class="regular-text code">
<p class="description" id="home-description">Enter the address here if you <a href="//codex.wordpress.org/Giving_WordPress_Its_Own_Directory">want your site home page to be different from your WordPress installation directory.</a></p>
</td>
</tr>
这是我的插件生成的自定义字段,我希望在其之后插入:<tr>
<th scope="row">Protocol Relative URL</th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>Protocol Relative URL</span></legend>
<label for="remove_http">
<input name="protocol_relative" type="checkbox" id="protocol_relative" value="1" checked="checked">Do not apply to external links
</label>
<p class="description">Only the internal links will be affected.</p>
</fieldset>
</td>
</tr>