$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Include a PHP file inside an array|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Include a PHP file inside an array

matteradmin8PV0评论

I'm trying to add a custom PHP script inside of the nav menu (before the closing ) and struggling.

Code here:

<?php
      wp_nav_menu(array(
                        'theme_location' => 'menu-1',
                        'menu_id' => 'primary-menu',
                        'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s<div class="my-div">' . $addCats . '</div></ul>'
                    ));
      $addCats = require_once('custom_menu_addon.php');
?>

The above code includes the file outside of the new added to the menu:

Any recommendations for getting this to print inside the div? Am I using the wrong command to pull the file contents there?

Thank you in advance for your help and guidance! <3

I'm trying to add a custom PHP script inside of the nav menu (before the closing ) and struggling.

Code here:

<?php
      wp_nav_menu(array(
                        'theme_location' => 'menu-1',
                        'menu_id' => 'primary-menu',
                        'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s<div class="my-div">' . $addCats . '</div></ul>'
                    ));
      $addCats = require_once('custom_menu_addon.php');
?>

The above code includes the file outside of the new added to the menu:

Any recommendations for getting this to print inside the div? Am I using the wrong command to pull the file contents there?

Thank you in advance for your help and guidance! <3

Share Improve this question asked Jan 18, 2019 at 5:12 AlexHighHighAlexHighHigh 1256 bronze badges 4
  • 1 You can't have a <div> as a direct child of an <ul>, that's invalid HTML. – fuxia Commented Jan 18, 2019 at 5:40
  • I'm aware, it's going to be further list items but at the moment im just testing what I can print. I was concerned I may have been printing closing tags and whats why it was breaking and therefore tried <div>s!.. – AlexHighHigh Commented Jan 18, 2019 at 7:08
  • What’s even in the PHP file? HTML? – Jacob Peattie Commented Jan 18, 2019 at 7:20
  • PHP, its a cool script we made to fetch categories etc. using it as a dropdown for the final item of the menu. Edited the answer below, seems to work well. Thanks guys! <3 – AlexHighHigh Commented Jan 18, 2019 at 8:35
Add a comment  | 

1 Answer 1

Reset to default -1

Please Use Below code

<?php
$addcats = array();
ob_start();
require 'custom_menu_addon.php';
$addCats = ob_get_clean();
wp_nav_menu(array(
    'theme_location' => 'menu-1',
    'menu_id' => 'primary-menu',
    'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s<div class="my-div">' . $addCats . '</div></ul>'
));

I've edited this answer after some research into the usage of this object array and put it in context with my code, works well on the site :)

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far