Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:02:37+00:00 2026-06-01T09:02:37+00:00

I want to add custom attribute settings to a generated anchor link of WordPress.

  • 0

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.

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.

My header.php file contains the following links to the needed Jquery libraries:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>

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)

    <script type="text/javascript">
                    $('.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');
                    });

        </script>

When checking the code via firebug WordPress generates the following code:

<ul>

                    <li class="page_item page-item-5"><a href="http://localhost/ddwp/?page_id=5">Home</a>
<ul class='children'>
<li class="page_item page-item-11"><a href="http://localhost/ddwp/?page_id=11">Link1</a></li>
</ul>
</li>
<li class="page_item page-item-17"><a href="http://localhost/ddwp/?page_id=17">Link2</a></li>
<li class="page_item page-item-21"><a href="http://localhost/ddwp/?page_id=21">Link3</a></li>
<li class="page_item page-item-23"><a href="http://localhost/ddwp/?page_id=23">Link4</a></li>
<li class="page_item page-item-62 current_page_item"><a href="http://localhost/ddwp/?page_id=62">Link5</a></li>
                </ul>

Thanks in advance!

Kind regards
Dragon54

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:02:39+00:00Added an answer on June 1, 2026 at 9:02 am

    There’s a few reasons your script isn’t working. Here’s some suggestions, and some code that is tested to apply the attributes you are after to the links in the navigation:

    1. You might consider moving the ready away from each separate call to a function that contains all of the calls rather than for each call separately. (I have done that below for you).
    2. .page_item is not a link, it is an li element. Also note that this is ONLY the navigation links – it will not apply to any links in the content of the pages/posts.
    3. Jquery in WordPress is not always safe to run using $. By wrapping the calls in a document ready called with jQuery, you can still use $ within the function to call the jQuery functions.

      jQuery(function($) {
          $('.page_item a').each(function(){
              $(this).attr('data-transition', 'pop');
              $(this).attr('data-icon', 'arrow-r');
              $(this).attr('data-iconpos', 'left');
              $(this).attr('data-role', 'button');
          });
      });
      

    EDIT :
    Per the excellent comments by @Jasper the much better way to do this would be:

    jQuery(function($) {
        $('.page_item a').attr({ 'data-transition' : 'pop', 
                'data-icon' : 'arrow-r', 
                'data-iconpos' : 'left', 
                'data-role' : 'button' });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want add my custom sidebar next right column all page. Please check this
I want to add a custom attribute / property into the manifest file, and
I want to add custom (compound and read-only) attributes to my stored procedure results
I want to know is there any way to add a custom attribute to
I want to add classes from System.Activites.Presentation my custom attribute. I tried to do
I'm adding a custom behaviorExtensionElement for WCF and want to add an attribute that
I want to add custom jump list entries to my application in Windows 7.
I am using C#.net I want to add custom edit/delete buttons to my GridView1
I want to add a custom configuration section in my app.config file. Is there
I want to add a custom model method to the admin filter, however it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.