• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

PHP in Header for Menu

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › PHP in Header for Menu

This topic is: not resolved

Tagged: menu, navigation, php

  • This topic has 10 replies, 2 voices, and was last updated 9 years, 3 months ago by Jon Schroeder.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • June 21, 2014 at 1:04 pm #110974
    boldplan
    Participant

    Right now I have an alternative for the main menu for Magazine. While I'd like to use the WordPress nav menu system, unfortunately Magazine contains a number of impracticalities, primarily the second menu. (I don't know why both weren't bootstrap or a pure css dropdown instead of a messy menu. I have now a CSS menu that works for my entire site, including the non-Wordpress portions, and I was hoping to use it instead of the current top navigation. It works with php include statement. While this was easy with standard wordpress templates I'm unsure how one would do this with the Genesis system, to put the php include for the menu at the top, below the body tag for Magazine (or any Genesis template for that matter.) Thanks for any help or pointing me to how this is done, which I couldn't find.

    June 21, 2014 at 3:57 pm #110982
    Jon Schroeder
    Member

    The Genesis Visual Hook plugin may help you to see which hook you'd want to use, but it'll be something like this in your functions.php file:

    add_action( 'genesis_header', 'yourprefix_add_secondary_menu', 20 );
    function yourprefix_add_secondary_menu() {
    // your php code here... e.g. include()...

    ?>
    <!-- or your markup here -->
    <?php
    }

    June 21, 2014 at 4:13 pm #110983
    boldplan
    Participant

    John - Thanks - unfortunately it's not working. Is the above code correct? I see an end php tag as well as an empty open. I'm not sure why the following would be necessary to close and open and seems unnecessary. I am guessing it is there to add markup in case I'd want between the PHP open and close tags - which is very helpful. Unfortunately I don't see the topnav.php file being executed and appearing in that top navigation spot. It's just a file with markup to be included as a top nav.

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    include ('/home/mysite/public_html/menu/topnav.php');
    }

    June 21, 2014 at 5:00 pm #110990
    Jon Schroeder
    Member

    Try echoing something instead of including the file. I have a feeling that's the issue. Once you've done that, you could put whatever you like in the function (perhaps the contents of the file), and then just call the function wherever else you want to add it.

    June 21, 2014 at 5:38 pm #110993
    boldplan
    Participant

    Jon - Thanks and good idea. I tried the following but don't see the text echoed to the screen either from the PHP or the HTML markup on the Magazine Pro theme. Theoretically it should work on any Genesis theme.

    // Add TOP NAV DROPDOWN MENU

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    echo "your php code here";

    ?>
    <h3>or your markup here</h3>
    <?php
    }

    June 21, 2014 at 6:33 pm #110996
    Jon Schroeder
    Member

    So if the include isn't the problem, then something else is. Make sure you're editing the child theme's functions.php file, first of all, and install the visual hooks plugin.

    June 21, 2014 at 8:51 pm #111015
    boldplan
    Participant

    Thanks for the help, truly. It's definitely the right child theme as screwing it up once confirmed with a nice white screen and error. 🙂 I even tried putting it in different places using the Visual Hook Guide and the text just doesn't seem to appear, even in the source code. It's why I'm asking the question here. From what I can see, this should do the trick, as is. Maybe I'm missing something. Maybe one of the parameters is incorrect? This is what frustrates me with Genesis themes - the incredibly simple becomes an exercise in backending your way into a theme.

    // Add TOP NAV DROPDOWN MENU

    add_action( ‘genesis_before_content’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    echo "Please work testing code!";

    ?>
    <h3>Please work testing code!</h3>
    <?php
    }

    June 21, 2014 at 9:52 pm #111018
    Jon Schroeder
    Member

    Huh. Everything looks right here to me, with the possible exception of the quote marks, if you copied and pasted directly.

    I'll take another look at this with fresh eyes tomorrow.

    June 23, 2014 at 3:26 am #111128
    boldplan
    Participant

    I tried a fresh install of the Magazine theme. I used the above code and pasted it into the functions.php at the bottom to make sure it was the last function processed. Didn't matter where I put it - the code never echoed to the screen, neither the PHP nor the HTML. I told you, replacing the top nav with my own was not easy! :/

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    echo "BLAH BLAH BLAH";

    ?>
    or your markup here
    <?php
    }

    June 27, 2014 at 12:03 am #111709
    boldplan
    Participant

    Finally got it to work. I had to put it after header I believe. I used Simple Genesis Hooks plugin - something like that - and then was able to infer what needed to be done in function form. For some reason, using what appears to be almost identical code (changing the function) and putting it in the right hook did the job. Thanks for the help along the way.

    June 27, 2014 at 11:06 am #111782
    Jon Schroeder
    Member

    Glad to hear that; the function name shouldn't matter, so I'm sure we were using the wrong hook is what happened. What was the right one?

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble