Skip to content

Instantly share code, notes, and snippets.

@cinghaman
Created August 31, 2012 02:46
Show Gist options
  • Save cinghaman/3548280 to your computer and use it in GitHub Desktop.
Save cinghaman/3548280 to your computer and use it in GitHub Desktop.
Dynamically populating href with jquery
This section goes into your body or where ever you want it to be displayed
<a href="" class="b-template" title="title" Preview</a>
<a href="" class="d-template" title="title" Preview</a>
<a href="" class="p-template" title="title" Preview</a>
<a href="" class="f-template" title="title" Preview</a>
---------------------------------------------------------
This would be added to your header section
jQuery(document).ready(function($)
{
var templateDir = '< ?php bloginfo('template_directory') ?>';
$('.b-template').each(function() {
($(this).attr('href', templateDir + '/_inc/images/imgage-file.png'));
});
$('.d-template').each(function() {
($(this).attr('href', templateDir + '/_inc/images/image-file-2.png'));
});
$('.p-template').each(function() {
($(this).attr('href', templateDir + '/_inc/images/image-file-3.png'));
});
$('.f-template').each(function() {
($(this).attr('href', templateDir + '/_inc/images/image-file-4.png'));
});
});
@cinghaman
Copy link
Author

to check full post with explanation visit my blog http://amancingh.com/blog/dynamically-populating-href-using-jquery-wordpress/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment