douyue8191 2013-10-03 20:11
浏览 51

在WordPress常规设置页面中订购输入字段

I have created a plugin that adds a input box, 'Logo URL' on the Settings > General page in WordPress. This input can be called and works correctly. I have created another plugin that pulls the 'Logo URL' and applies the path to pull an image for the Login screen. Everything appears peachy.

The only issue I am having is that I would like to move the 'Logo URL' on the Settings > General page to up under 'Site Address (URL)'. I am at a loss on how to do this. I have scoured the web and been unable to find a helpful answer.

I am currently removing the original General page and adding a New General page but am unsure how to parse the correct options-general.php.

How to move the Logo_URL higher on the General Page?

/**
  * 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 . '" />';
    }
}
  • 写回答

1条回答 默认 最新

  • dqde43215 2013-10-03 23:41
    关注

    No, there's no way of ordering that natively. WordPress first prints its stuff then ours. It has to be done with 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
    });
    

    The recommended way is to enqueue the JS inside an action call for "admin_print_scripts-$hookname". Note the hook name use in admin_footer and admin_head too.

    As your field only changes after the page loaded, we can notice the "jump". To smooth it, we can use:

    add_action( 'admin_head-options-general.php', function()
    {
        echo '<style>#wpbody .wrap form{display:none}</style>';
    });
    

    And add this jQuery after replaceWith():

    $('#wpbody .wrap form').fadeIn('slow');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据