Skip to content

Instantly share code, notes, and snippets.

@MWDelaney
Created July 21, 2018 19:55
Show Gist options
  • Select an option

  • Save MWDelaney/074f6bf57b2b29bc3617a6e1174b32fd to your computer and use it in GitHub Desktop.

Select an option

Save MWDelaney/074f6bf57b2b29bc3617a6e1174b32fd to your computer and use it in GitHub Desktop.
<?php
namespace App;
/**
* Set the Flexbox "order" of half the menu-items so that we can center the logo between them.
*/
add_action( 'wp_enqueue_scripts', function() {
// Get menu object
$theme_locations = get_nav_menu_locations();
$menu = get_term( $theme_locations['primary_navigation'], 'nav_menu' );
// Set up the CSS to return
$custom_css = "
.navbar-nav li:nth-of-type(n+" . floor(($menu->count/2) +2) . ") {
order: 2;
}
";
// Register a style to add inline styles after
wp_register_style( 'my-inline-style', false );
// Enqueue the style
wp_enqueue_style( 'my-inline-style' );
// Add our inline styles
wp_add_inline_style( 'my-inline-style', $custom_css );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment