Skip to content

Instantly share code, notes, and snippets.

@westcoastdigital
Created August 29, 2018 05:42
Show Gist options
  • Select an option

  • Save westcoastdigital/1ff6db9e4673b18ceb8bbd7b4868b248 to your computer and use it in GitHub Desktop.

Select an option

Save westcoastdigital/1ff6db9e4673b18ceb8bbd7b4868b248 to your computer and use it in GitHub Desktop.
Move logo to middle of menu in GeneratePress
(function($) {
$(function() {
/**
* Move logo to middle of menu
*/
wcd_move_logo();
$(window).resize(function() {
var exists = $("#primary-menu .menu li.menu-logo").length;
// check if isnt already in menu and if isnt then move
if (exists == 0) {
wcd_move_logo();
}
});
});
function wcd_move_logo() {
// checks the widow size is greater than 768px
if ($(window).width() > 768) {
var menuCount = $("#primary-menu .menu li").length,
logoPosition = menuCount / 2,
logo = $(".site-logo").html(),
logoInsert = '<li class="menu-item menu-logo">' + logo + "</li>";
if (menuCount > 1) {
$(logoInsert).insertAfter(
"#primary-menu .menu li:nth-child(" + parseInt(logoPosition) + ")"
);
$(".inside-header").hide();
}
} else {
var logo = $(".site-logo");
$(logo).insertBefore(".inside-navigation .menu-toggle");
$(".inside-header").hide();
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment