1

I want to create the ghost page /foo/ so that it appears in the list of pages, but is unclickable and has no content.

An example use of this is that in my menu it displays the pagename foo and when you hover it, it displays the subpages (which are "real" pages) bar and baz. The URLs of them would be /foo/bar/ and /foo/baz/.

I figured I could simply remove the <a> tags of foo in Javascript and put a redirect in the /foo/ page. but that doesn't feel right. What would be an elegant/serverside solution for this problem?

  • Please show us your code. Are trying to that in a menu? If so, in which menu? Is this admin or theme facing, etc? This question needs a huge edit and lots of additional information. – kaiser Sep 30 '13 at 12:36
2

You can do it this way. check for a unique class for the page in the menu or add an unique class. you can do it by checking CSS classes under screen options in the menu edit page.

lets say the class you added is ghost-page

Then in the js file

jQuery(document).ready(function(){
    jQuery('.ghost-page').on('click', function(e){
        e.preventDefault(); 
    });
});

But the page will still be accessible by home_url()/page-slug but the above will disable the click event from the menu for this page.

But if you don't want a page to exist then, add a custom link to the menu with # in the url and add the css class and label as foo, by doing so there wont be a page to link with and the above js code will disable the click event.

enter image description here

Hope it helps!

  • Hmm, if this is the only solution I'm a bit disappointed in the flexibility of Wordpress. – Joren Sep 30 '13 at 12:02
  • I guess I have found a better solution. I have improved the answer. pls check the bottom of the previous answer. – Maruti Mohanty Sep 30 '13 at 12:12
  • You can't put a # in the URL. – Joren Sep 30 '13 at 13:22
  • You can while creating a custom link for a menu. – Maruti Mohanty Sep 30 '13 at 13:25
  • Added an image in the answer... Hope it helps – Maruti Mohanty Sep 30 '13 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.