Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Code to add a bit of code to all image post via child theme WordPress

  • SOLVED

Hello All,

I am using the Karma theme from truethemes.

I can have photos pop up with the prettyphoto effect but I have to manually add data-gal="prettyPhoto" to the <a href...> code.

I need code to automatically add data-gal="prettyPhoto" to all the <a href...> codes when I add an images to posts.

I am using the child theme of Karma and I hope this code could be added to that instead of the main theme, but if not possible, such is life. Possible even make it a small plugin.

I think it is a small batch of code but could be wrong.

If you want to get ambitious, make it so it treats all images in a particular post as a gallery and you can cycle through them as such. ie (previous) (next) functionality.

Thanks for looking.

site: http://pleinairbc.com

ref: http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

Answers (2)

2012-05-18

Gabriel Reguly answers:

Hi,

Have you tried the Fancybox for WordPress plugin?

[[LINK href="http://wordpress.org/extend/plugins/fancybox-for-wordpress/"]]http://wordpress.org/extend/plugins/fancybox-for-wordpress/[[/LINK]]

Regards,
Gabriel


mrking comments:

no, as i thought it might conflict and the styles would be different.


Gabriel Reguly comments:

Hi,

Sorry if I can't be more helpful, but $5 is not much of a prize.

Good luck,
Gabriel


Gabriel Reguly comments:

Hi,

Have you tried this code?


<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a:has(img)").prettyPhoto();
});
</script>


First, for a quick test, add it to your header.php file. Then if it works, load it properly via wp_enqueue_script() in your functions.php, e.g., something like


function my_scripts_method() {
wp_enqueue_script(
'custom-script',
get_template_directory_uri() . '/js/custom_script.js',
array('jquery')
);
}
add_action('wp_enqueue_scripts', 'my_scripts_method');


Good luck,
Gabriel


mrking comments:

Thanks Gabriel. I tried the head route to test but with no success. For the heck of it I added the script to the functions file instead. Still no go.

Thanks for the effort.

I'll take your initial advice and just use Fancybox plugin.


Gabriel Reguly comments:

Hi,

Good to hear that you are happy with the easiest solution.

Please do not forget to vote for me: [[LINK href="http://wpquestions.com/question/pickAWinner/id/3972"]]http://wpquestions.com/question/pickAWinner/id/3972[[/LINK]].

That is the same link as 'Vote to award prize' near to 'Edit' link ;-)

Regards,
Gabriel


mrking comments:

Yup, already did.

2012-05-18

petrisor Daniel answers:

Why don't you use Lightbox. You don't need to insert anything in your code. Plugin makes everything.