我创建了一个插件,在WordPress的"设置>常规"页面上添加一个输入框"徽标URL"。可以调用此输入并正常工作。我创建了另一个插件,该插件拉取"徽标URL"并应用路径为登录屏幕拉取图像。一切都显得桃色。
我遇到的唯一问题是我想将"设置>常规"页面上的"徽标 URL"移动到"站点地址 (URL)"下。我不知道该怎么做。我在网上搜索了一下,但找不到有用的答案。
我目前正在删除原始的常规页面并添加一个新的常规页面,但不确定如何解析正确的选项-常规.php。
如何在常规页面上将Logo_URL移得更高?
/**
* This is the code to create the Settings box on the Settings > General
*/
$new_general_setting = new new_general_setting();
class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'URL_logo', 'esc_attr' );
add_settings_field('URL_logo', '<label for="URL_logo">'.__('Website logo (URL)' , 'URL_logo' ).'</label>' , array(&$this, 'fields_html') , 'general' );
}
function fields_html() {
$value = get_option( 'URL_logo', '' );
echo '<input type="text" id="URL_logo" name="URL_logo" value="' . $value . '" />';
}
}
不,没有办法在本地订购。WordPress首先打印它的东西,然后打印我们的东西。它必须用jQuery来完成。
add_action( 'admin_footer-options-general.php', function()
{
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
var son = $("label[for='URL_logo']").parent().parent(); // Our setting field
var father = $("label[for='home']").parent().parent(); // WordPress setting field
son.insertAfter(father);
});
</script>
<?php
});
推荐的方法是在 "admin_print_scripts-$hookname"
的操作调用中将 JS 排队。请注意钩子名称在admin_footer
和admin_head
中使用的。
由于您的字段仅在页面加载后更改,因此我们可以注意到"跳转"。为了平滑它,我们可以使用:
add_action( 'admin_head-options-general.php', function()
{
echo '<style>#wpbody .wrap form{display:none}</style>';
});
并在replaceWith()
后添加此jQuery:
$('#wpbody .wrap form').fadeIn('slow');