Search code examples
wordpressbookmarklet

Right angle bracket in a bookmarklet in Wordpress


I'm trying to include a JavaScript bookmarklet in my Wordpress post. The bookmarklet uses jQuery with a child selector ">" (right angle bracket) and looks something like this:

<a href="javascript:$('ul>li') ...">Bookmarklet</a>

But when I use the right angle bracket in there, it messes up the page layout and the bookmarklet element doesn't actually appear in the post.


Solution

  • Figured it out with a tip from Sharif.

    The ">" symbol can't be included in the href attribute of an element in WordPress (at least not in my instance?). But it's possible to add a script right after the element that modifies its href attribute to whatever value we want.

    Thus, the structure of the final code is:

    <a href="whatever" id="uniqueid">Bookmarklet</a>
    <script> document.getElementById("uniqueid").href = "javascript:$('ul>li')..."; </script>