WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add an id to each permalink from a plugin. Jquery just returns the same id for each link. Is there another way I can do this?

add_action('add id for each loop', 'test');
function test() {
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>


   $("a").attr('id', '<?php the_ID(); ?>');


It works fine if I add it to the template directly so is there a way I can find the code from a plugin and add/edit into content.php (custom? loop) template file?

// add the id
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
// result
<a href="<?php the_permalink(); ?>" id="<?php the_ID(); ?>"><?php the_title(); ?></a>
share|improve this question

I know add id for each loop is not an existing hook I just put it there as I was hoping someone could tell me the right hook to use. To give you more a sense of what I am trying to do. hopefully this link will help. I have everything working just trying to port/move it to a plugin. As for re-loading jquery I found it didn't work on a previous code so I will re-examine it.

So its impossible to modify a template file from a plugin? could I reset the query and make a new loop in the plugin to add the id? Link

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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