0

Similar to my previous question, I want to print a list of all of the submenu items in the Dashboard like so:

  • Updates > update-core.php
  • Library > upload.php
  • Add New > media-new.php
  • etc...

This is what I have so far:

global $submenu;
foreach ( $submenu as $group => $item ) {
    echo '<pre>'; print_r( $item ); echo '</pre>';
}
// echo '<pre>'; print_r( $submenu ); echo '</pre>';

Output

Array (
    [0] => Array (
            [0] => Home
            [1] => read
            [2] => index.php
        )

    [10] => Array (
            [0] => Updates 4
            [1] => update_core
            [2] => update-core.php
        )

)
Array (
    [5] => Array (
            [0] => Library
            [1] => upload_files
            [2] => upload.php
        )

    [10] => Array (
            [0] => Add New
            [1] => upload_files
            [2] => media-new.php
        )

)
AND SO ON...

I know it's a matter of playing around with the foreach and using the right index like my previous question, but I am having trouble with it. Any help and guidance is much appreciated.

2

If you want them in an unordered list:

echo "<ul>\r\n";
foreach ( $submenu as $group => $item ) {
    foreach ( $submenu[$group] as $key => $value ) {
        echo "<li>" . $submenu[$group][$key][0] . " > " . $submenu[$group][$key][2] . "</li>\r\n";
    }
}
echo "</ul>";

This results in:

<ul>
<li>Home > index.php</li>
<li>Updates > update-core.php</li>
<li>Library > upload.php</li>
<li>Add New > media-new.php</li>
</ul>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.