There is a menu, and one element is added to it using the script, and the unnecessary is deleted.

There are no problems with adding an item, but there are difficulties with deleting.

The menu from the WordPress is horizontal, I added a page, and it adds an item with a link to the page, I removed the title, but still the menu moved slightly. How to create a page without adding to the menu, I do not know, or rather the methods I know are not satisfied, so I want to remove the script.

<script type="text/javascript" language="javascript"> $(document).ready(function(){ //удаляем "ненужное"(не работает) $(".page_item page-item-716").remove(); //добавляем первый пункт в блок ul $('<li><a href="#">Добавили скриптом</a></li>').prependTo('.menu > ul'); }); </script> <div class="menu"> <ul> <li><a href="#">Добавили скриптом</a></li> <li class="page_item page-item-2"><a href="#" title="р1">р1</a></li> <li class="page_item page-item-17"><a href="#" title="р2">р2</a></li> <li class="page_item page-item-89"><a href="#" title="р3">р3</a></li> <li class="page_item page-item-91"><a href="#" title="р4">р4</a></li> <li class="page_item page-item-716"><a href="#" title="">вот этот пункт вместе с ли надо вообще удалить, но не получается </a></li> </ul></div> 

UPD

remove () - works quite well. I think the problem is in the class name with a space, how can I get around this? (removing the space is not an option)

    3 answers 3

      $(".page_item page-item-716").remove(); //исправить на: $(".page_item .page-item-716").remove(); 

    in html in class = "class1 class2", means that this element belongs to two classes. In jQuery, the class selector is denoted by the symbol: "."

    • pancake. thank. I rummaged a little myself and found that the $ (". page-item-716") record. remove (); - the problem is solved - silksofthesoul

    It is even easier to register in css .page_item .page-item-716 {display: none}, why should the script do this?

    • also an option ... a good idea, in fact, since few of the scripts will be turned off by anyone.) thank you too) - silksofthesoul

    why not delete this menu item in wordpress itself?

    • This is a page from the banner, the interface should be saved, but when you add a page, it automatically throws it in the menu. You cannot edit this menu with WordPress admin tools, but I know there is a way to enable this editing via functions.php, but I turned it on somehow, and WordPress began to work extremely unstable, poured the site itself and the admin panel with it. While there is no urgent need (only one point, done quickly) in addressing this issue in other ways - not worth it. Will rise will decide differently. so far - "on scotch".)) - silksofthesoul
    • On the menu edit page there is the item "Automatically add new top-level pages", is it a tick? - deamondz
    • there is no. in the menu editing panel, there is generally the top menu (well, this is my top one, and this is how it is most important), it cannot be edited. I have never met the options you described in the admin panel. WordPress 3.2.1. - silksofthesoul