Support

Account

Home Forums Add-ons Options Page Change Menu Position of Options Page

Solved

Change Menu Position of Options Page

  • If I want to change position of the ‘Options Page’ to appear under the Dashboard… How can we do that? Can you please help.
    Thanks

  • Hi @amanvirk1982

    Thanks for the question. I found a few tutorials which looked at customizing the menu item order. Then with a bit of PHP, I came up with this code to remove the current ACF item, then add it back in after the dashboard:

    
    function custom_menu_order( $menu_ord ) {  
        
        if (!$menu_ord) return true;  
        
        
        // vars
        $menu = 'edit.php?post_type=acf';
        
        
        // remove from current menu
        $menu_ord = array_diff($menu_ord, array( $menu ));
        
        
        // append after index.php [0]
        array_splice( $menu_ord, 1, 0, array( $menu ) );
        
        
        // return
        return $menu_ord;
    }  
    add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order  
    add_filter('menu_order', 'custom_menu_order');  
    

    Links:
    http://wp.tutsplus.com/tutorials/creative-coding/customizing-your-wordpress-admin/
    http://stackoverflow.com/questions/1883421/removing-array-item-by-value
    http://stackoverflow.com/questions/3797239/insert-new-item-in-array-on-any-position-in-php

    Thanks
    E

  • Thanks for looking into it. Actually I wanted to change position of options page. It is currently changing position of ‘custom fields’ menu. Here are the slugs that I am using for custom option pages, if these help.

    admin.php?page=acf-options-header
    admin.php?page=acf-options-home-page-slider
    admin.php?page=acf-options-footer

    I tried replacing edit.php?post_type=acf with the above slugs, but didn’t work.

    Thanks

  • I have been experimenting with this also with no success. Anyone have any luck cracking this. I too am trying to change the menu position of the “options” menu (from the options add-on), not the custom fields. Any help is greatly appreciated.

  • Hi guys.

    I think the above code should work, perhaps you need to test that the options pages have been added at the time which this filter runs like so:

    
    <?php 
    
    echo '<pre>';
    	print_r( $menu_ord );
    echo '</pre>';
    die; ?>
    

    You may find that the options pages are not in this array. If not, then the filter is running to early. Set the $priority of the filter to a later one like so:

    
    add_filter('menu_order', 'custom_menu_order', 99);  
    

    Thanks
    E

  • I am still very interested in finding a solution to this however Elliot, what you stated above went right over my head. It is possible you could consolidate it into a working technique…

    Any help is greatly appreciated.

  • Hey guys,

    Just got this working, the options page is in the array at the time the filter runs, you’ve just got to set the ‘slug’ correctly.

    By including Elliot’s array output snippet into the function like so:

    
    function custom_menu_order( $menu_ord ) {  
        
        if (!$menu_ord) return true;  
        
        // vars
        $menu = 'acf-options';
        
        // remove from current menu
        $menu_ord = array_diff($menu_ord, array( $menu ));
        
        // append after index.php [0]
        array_splice( $menu_ord, 1, 0, array( $menu ) );
        
        echo '<pre>';
        print_r( $menu_ord );
        echo '</pre>';
        die;
        
        // return
        return $menu_ord;
    }  
    
    add_filter('custom_menu_order', 'custom_menu_order');
    add_filter('menu_order', 'custom_menu_order');
    

    and refreshing the wp-admin, output an array like so:

    
    Array
    (
        [0] => index.php
        [1] => acf-options
        [2] => separator1
        [3] => edit.php
        [4] => edit.php?post_type=profiles
        [5] => edit.php?post_type=places
        [6] => upload.php
        [7] => edit.php?post_type=museum
        [8] => link-manager.php
        [9] => edit.php?post_type=page
        [10] => edit-comments.php
        [11] => separator2
        [12] => themes.php
        [13] => plugins.php
        [14] => users.php
        [15] => tools.php
        [16] => options-general.php
        [17] => edit.php?post_type=acf
        [18] => separator-last
        [19] => sitepress-multilingual-cms/menu/languages.php
        [20] => WP-Optimize
    )
    

    which reveals that my slug is [1] => acf-options

  • Thanks owen.hoskins for the help.
    Here’s the final code that work:

    function custom_menu_order( $menu_ord ) {  
        
        if (!$menu_ord) return true;  
        
        
        // vars
        $menu = 'acf-options';
        
        
        // remove from current menu
        $menu_ord = array_diff($menu_ord, array( $menu ));
        
        
        // append after index.php [0]
        array_splice( $menu_ord, 1, 0, array( $menu ) );
        
        
        // return
        return $menu_ord;
    }  
    add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order  
    add_filter('menu_order', 'custom_menu_order');
  • @elliot I think this could be simplified by adding a filter to the code so we can set the menu position when the menu item is registered:

    $parent_page = add_menu_page( $this->settings['title'], $this->settings['menu'], $this->settings['capability'], $this->settings['slug'], array($this, 'html'), '', apply_filters('acf/options_page/menu_position', null));

    The list of available positions is here:

    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters

    e.g. To position it after “Dashboard” you can set the position to 3:

    add_filter('acf/options_page/menu_position', function() { return 3; });

    What do you think?

    Thanks!

  • Hi @DaveAlberon

    I like the idea, I’ll add it to the to-do.

    Cheers
    E

  • Was this idea actually implemented? Being able adjust position of option page in menu is nice thing…

  • I found you can also pass icon_url, and position.

    E needs to update the docs. 🙂

        acf_add_options_page( array(
    
            'page_title' 	=> 'Home Page Sliders',
            'menu_title' 	=> 'Sliders',
            'menu_slug' 	=> 'home-page-sliders',
            'capability' 	=> 'edit_posts', 
            'icon_url' => 'dashicons-images-alt2',
            'position' => 7
    
        ) );
  • If anyone wants to put Options page into ie. Appearance menu, use ‘parent_slug’ param.

  • For anyone else looking for this (I was looking to add options menu under CPT menu) I came across the solution on Jared Atchison’s site
    Here

  • For anyone else looking for a solution, this is working for me

    if( function_exists(‘acf_add_options_page’) ) {
    acf_add_options_page( array(
    ‘page_title’ => ‘School Options’,
    ‘position’ => 3
    ) );
    }

Viewing 15 posts - 1 through 15 (of 15 total)

The topic ‘Change Menu Position of Options Page’ is closed to new replies.