Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding attributes to an anchor in Wordpress
    primarykey
    data
    text
    <p>I want to add custom attribute settings to a generated anchor link of Wordpress. This is to let Jquery Mobile find the attributes and makes a button out of it.</p> <p>Every anchor link, which is generated in Wordpress via PHP, contains the page_item class. So my guess is to search for the needed 'page_item' class and just add the needed attribute information to generate the needed button.</p> <p>My header.php file contains the following links to the needed Jquery libraries:</p> <pre><code>&lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"&gt;&lt;/script&gt; </code></pre> <p>I wanted to use the following code to add attributes to my anchor links but I just can't seem to let it work. (This code is placed in the header of the header.php file)</p> <pre><code> &lt;script type="text/javascript"&gt; $('.page_item').ready(function(){ $(this).attr('data-transition', 'pop'); $(this).attr('data-icon', 'arrow-r'); $(this).attr('data-iconpos', 'left'); $(this).attr('data-role', 'button'); }); &lt;/script&gt; </code></pre> <p>When checking the code via firebug Wordpress generates the following code:</p> <pre><code>&lt;ul&gt; &lt;li class="page_item page-item-5"&gt;&lt;a href="http://localhost/ddwp/?page_id=5"&gt;Home&lt;/a&gt; &lt;ul class='children'&gt; &lt;li class="page_item page-item-11"&gt;&lt;a href="http://localhost/ddwp/?page_id=11"&gt;Link1&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="page_item page-item-17"&gt;&lt;a href="http://localhost/ddwp/?page_id=17"&gt;Link2&lt;/a&gt;&lt;/li&gt; &lt;li class="page_item page-item-21"&gt;&lt;a href="http://localhost/ddwp/?page_id=21"&gt;Link3&lt;/a&gt;&lt;/li&gt; &lt;li class="page_item page-item-23"&gt;&lt;a href="http://localhost/ddwp/?page_id=23"&gt;Link4&lt;/a&gt;&lt;/li&gt; &lt;li class="page_item page-item-62 current_page_item"&gt;&lt;a href="http://localhost/ddwp/?page_id=62"&gt;Link5&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Thanks in advance!</p> <p>Kind regards Dragon54</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload