Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
<script>
$(document).ready(function(){

 $("a").each(function(){

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

}

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

1 Answer 1

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

 
discard

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.