• Resolved heavym

    (@heavym)


    Good Afternoon,

    The below block of code is used to display the parent page and submenu pages in list format. Rather than pasting this on each of my different templates, I would like to paste it once in say the function.php theme file and then use an action hook single line of code to call it on each of the templates.

    I understand the idea of how this works but in practice it doesnt for me.

    <?php
    if($post->post_parent)
    $children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
    else
    $children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
    if ($children) { ?>

      <?php echo $children; ?>

    <?php } ?>

    In the functions.php file I added the code with function mycustom_menu() { in front of it, and } after it. And yes their already is a function.php file with code in it, so all of this code above is between and initial opening php and closing php.

    Then in my template where I want to call it I put: <?php do_action('mycustom_menu'); ?>

    But it did not display. Is their a better way to go about this, or different syntax needed? Thanks!

    Cheers,
    Christopher

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter heavym

    (@heavym)

    Oh and to note if in the function I write: echo '<div id="random">test</div>'; for instance that does work. If I do an echo for the code above however it just spits out the actual code rather than rendering it.

    I’ve tried echoing just the divs, and no the php code, but the page continues to go blank. Any ideas? Thank you!

    Cheers,
    Christopher

    Thread Starter heavym

    (@heavym)

    Spoke with a PHP guy, had to change the code a bit by echoing HTML lines and not others. So was just a matter of syntax.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get an Action Hook to work as expected?’ is closed to new replies.