Home Forums Add-ons Options Page Add custom message to option page


Add custom message to option page

    • roby94

    • March 19, 2017 at 12:47 am


    I need to add a custom message to the top of option page.
    I need to use some php code to display some values in the message box, there is any way to do it?

    Thank yuo

  • There isn’t anything built into ACF that will let you alter the options page to add a message to the top. A while back I posted an example of how this can be accomplished in my example acf filters and function repo on github

    • roby94

    • March 19, 2017 at 2:44 am

    Hi John!

    Thank you for your reply, it is exactly what i was looking for. I’ve got a small question. If i use it on top level page, it works perfectly, but i can’t make it works with sub option page.

    My code is:

    if( function_exists('acf_add_options_page') ) {
            'page_title' 	=> 'Impostazioni',
            'menu_title'	=> 'Impostazioni',
            'menu_slug' 	=> 'theme-trends-settings',
            'capability'	=> 'edit_posts',
            'redirect'	=> false
            'page_title' 	=> 'Forms',
            'menu_title'	=> 'Forms',
            'parent_slug'	=> 'theme-trends-settings',
            'page_title' 	=> 'Gestione livelli abbonamenti',
            'menu_title'	=> 'Gestione livelli abbonamenti',
            'parent_slug'	=> 'theme-trends-settings',
            'menu_slug'     => 'gestione-livelli-abbonamento'
    	add_action('theme-trends-settings_page_gestione-livelli-abbonamento', 'before_acf_options_page', 1);
    function before_acf_options_page() {}
    add_action('theme-trends-settings_page_gestione-livelli-abbonamento', 'after_acf_options_page', 20);
    function after_acf_options_page() {}

    What i’m doing wrong?
    Thank you

  • Some of this is guess work, but the hook should be what you have.


    If you want to do some testing, open the ACF file
    on line 459 you’ll find the function html

    function html() {
    		// add this line to test
    		echo '<br><br>',current_filter(),'<br><br>';

    if you temporarily add the above test code the hook that is being used to display the options page will be output at the top of your options page. I’d be curious to know what it is.

    • roby94

    • March 19, 2017 at 3:15 am

    Thank you John!!
    Using the current_filter() i’ve founded was i was doing wrong. The right one is:

    Basically it doesn’t use the “menu_slug” but use “menu_title”. (Maybe is my fault because i’ve used two different names).

    Anyway thank you very much!

  • That’s curious, when I test this it uses the menu slug every time.

  • So basically it’s a WordPress hook (not ACF hook), reference:

    Top level pages	admin.php?page={page_slug}	toplevel_page_{page_slug}
    Sub pages	admin.php?page={page_slug}	{parent_slug}_page_{page_slug}

    Thank you @hube2 for this ! 🙂

    @roby94 reference says it is using slugs, and your final code does not corresponde with your initial code, so I just don’t believe it started using titles, that would be horrible approach.

    • storm

    • November 20, 2020 at 9:33 am

    @jave-web , @roby94 is actually right. This was really annoying for me so I tracked it down.

    wp-admin/includes/plugin.php on line 1328 (5.5.3)
    $admin_page_hooks[ $menu_slug ] = sanitize_title( $menu_title );

    current_filter will return the correct filter but the correct way is
    sanitize_title( $parent['menu_title'] ) . '_page_' . $child['page_slug']

  • @storm Well, in wp-admin/includes/plugin.php the get_plugin_page_hook()‘s doc.comments specifically state it’s a slug, get_plugin_page_hookname() also mentions those are slugs, and the code you’ve posted yourself is just storing the title – but – it is storing it under a slug – so the key of the hook is from the slug.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.