The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Magic Line in WordPress with pages not in the menu

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #32627

    Hi, I’m building a wordpress site with the magic line trick, and so far it looks pretty awesome, I love jQuery.

    I hate to be a pain but on my site there are some pages that are not available in the menu (such as blog posts, shop pages, etc) and when I’m on one of those the magic line just sticks off to the left side of the window.

    I was wondering if there is any way that I can get the line to still work and maybe stick under one of the other pages while surfing these non-main-menu pages? Because the red line looks for the current_page_item, and that is not always the case. I’m looking for some way to either make the magic line understand that a news post is under the News-page, or do some dirty fix where the news posts have the line under News.

    If I navigate to News, the red line moves under news and sticks there. However, if I then click on one of the blog posts to view it as a single post, the red line just sticks to the left side of the window.

    Im sorry if this was formulated poorly, here is the link to my page.


    Try adding this code just below the ‘$(function() {‘

    if ( $('.current_page_item').length() < 0 ) {
    $('#menu-main li:first').addClass('current_page_item');

    Hope this helps,


    Hi, thanks for the help but it doesn’t work. Instead it makes all jQuery (including the magic line) to break. This is my code:


    /*if ( $('.current_page_item').length() < 0 ) {
    $('#menu-main li:first').addClass('current_page_item');

    var $el, leftPos, newWidth,
    $mainNav = $("#menu-main"),
    $mainNav2 = $("#example-two");

  • ");

    var $magicLine = $("#magic-line");

    .css("left", $(".current_page_item a").position().left)
    .data("origLeft", $magicLine.position().left)
    .data("origWidth", $magicLine.width());

    $("#menu-main li").find("a").hover(function() {
    $el = $(this);
    leftPos = $el.position().left;
    newWidth = $el.parent().width();

    left: leftPos,
    width: newWidth
    }, function() {
    left: $"origLeft"),
    width: $"origWidth")


    Bump? Anyone?


    This post is too old for this reply BUT — I had to use two functions
    on functions.php of my theme

    function add_classes_on_li($classes, $item, $args) {
        if(!in_array('current-menu-item', $classes)){
              add_filter('wp_nav_menu', 'add_first_and_last');
      return $classes;
    function add_first_and_last($output) {
      $output = preg_replace('/class="menu-item/', 'class="current-menu-item menu-item', $output, 1);
      return $output;

    I hope it helps.. My problem came when the magic line refused to move on hover… :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.