Community Forums › Forums › Archived Forums › Design Tips and Tricks › Can anyone help with a php question?
Tagged: php menu site title
- This topic has 2 replies, 2 voices, and was last updated 8 years, 5 months ago by AMS.
-
AuthorPosts
-
October 25, 2015 at 10:12 am #168977AMSParticipant
I'm using the Minimum Pro theme, which I've been customizing. For my internal pages, I want to put the the site title and the main navigation above the header, with only the particular page name (post title) in the header itself. This is what I have so far, added to the functions.php:
add_action( 'genesis_before_header', 'not_front_page' );
function not_front_page() {
if ( ( !is_front_page() ) ) {
add_action( 'genesis_site_title', 'genesis_do_post_title', 1 );
add_action( 'genesis_before_header', 'genesis_seo_site_title', 1 );
add_action( 'genesis_before_header', 'genesis_do_nav', 2 );
}
}So far, so good, but I can't get the two elements (title and nav) to be on the same line and centered on the page using only CSS. I tried to get a div to wrap around both the site title and the main nav by doing this:
add_action( 'genesis_before_header', 'not_front_page' );
function not_front_page() {
if ( ( !is_front_page() ) ) {
add_action( 'genesis_site_title', 'genesis_do_post_title', 1 );
echo '<div class="wrap top-inner-page">';
add_action( 'genesis_before_header', 'genesis_seo_site_title', 1 );
add_action( 'genesis_before_header', 'genesis_do_nav', 2 );
echo '</div>';
}
}but the second "echo" ('</div>') seemed to execute immediately after the first, and BEFORE the two add actions (for the site title and the main nav).
Any suggestions would be greatly appreciated!
October 25, 2015 at 2:07 pm #168987PorterParticipantI believe the second echo is firing because add_action is firing after all of this code, it's essentially putting it in queue to be executed later, with the numeric value being it's priority in that list - either way, it happens after, 1, or 100.
This might not be the perfect way to accomplish what you're doing, but here's an idea to get around what's happening:
add_action( ‘genesis_before_header’, ‘not_front_page’ 1); function not_front_page() { if (!is_front_page()) { add_action( ‘genesis_site_title’, ‘genesis_do_post_title’, 1 ); echo ‘<div class=”wrap top-inner-page”>'; add_action( ‘genesis_before_header’, ‘genesis_seo_site_title’, 2 ); add_action( ‘genesis_before_header’, ‘genesis_do_nav’, 2 ); add_action( 'genesis_before_header', 'close_not_front_page', 3) } } function close_not_front_page() { echo ‘</div>'; }
I have no idea if that will work, but the logic is we're calling the main function with priority 1, so it all happens first. Then functions calls within 1, are set to 2, so they fire after the div, but before the close div, and the closing div is wrapped in a function with priority 3, so that it fires last. The "close_not_front_page" function literally serves to add a closing div, and has priority 3, so it fires at the end.
Again, I have no idea if that will actually work, and I doubt it's the most elegant solution, but it might work. If it doesn't, try altering the logic a bit to see if we're on the right track. Lastly, I remove a pair of brackets around your if, as they aren't needed. (!is_front_page) and ((!is_front_page)) are the same thing.
October 25, 2015 at 3:41 pm #168989AMSParticipantThanks for the suggestion. I'll give it a shot and let you know how it turns out.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.