1

I am no beginner Wordpress developer by any means but I am completely stuck with this. I have tried an array of alternatives without any result (href="#", href="#void", etc.).

I need "javascript:void(0);" as the href attribute in a HTML link. Inserting this in the text editor, flicking to the visual then back to the text editor makes it disappear.

I have read up some information on it (re: esc_url) but can't seem to find a fix. Is there a way for me to make this work on a Page in Wordpress somehow by way of a function or script?

The link I am trying to generate is: <a href="javascript:void(0);"> subscribe </a>

Thanks in advance.

3
  • 1
    Can you explain why do you need this. There are too many ways to achieve the goal: a plugin, data-* attribute and jQuery, hardcoding in the template upon some condition, custom field, disabling content filtering (very bad idea) and many more. – Max Yudin Jul 2 '19 at 10:29
  • I agree with Max, this shouldn't be necessary. This answer from SO is a good explanation of why: stackoverflow.com/a/1293130 – Jacob Peattie Jul 2 '19 at 12:11
  • Thanks peeps. I tried the link without the href in it and it actually worked fine. I can't believe I wrecked my head over this. 🙄 – lightpurpple Jul 4 '19 at 14:40
0

I also can't stand the fact the Wordpress removes "javascript:void(0);" from my hrefs (or anything else TBH...) upon saving or using the visual editor.

I just started using the Raw HTML plugin that does the job. I enclosed my code in [raw] ... [/raw] codes, and did NOT use the visual editor. My "voids" remain now! :)

0

we use javascript:void(0); to prevent the default operation of page and link it to the click or other js action. So the workaround for removal of javacript:void(0); for me was to use # in the href and then use e.preventDefault(); in the js action.

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.