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


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.



Answers (2)


Gabriel Reguly answers:


Have you tried the Fancybox for WordPress plugin?

[[LINK href=""]][[/LINK]]


mrking comments:

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

Gabriel Reguly comments:


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

Good luck,

Gabriel Reguly comments:


Have you tried this code?

<script type="text/javascript" charset="utf-8">

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() {
get_template_directory_uri() . '/js/custom_script.js',
add_action('wp_enqueue_scripts', 'my_scripts_method');

Good luck,

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:


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

Please do not forget to vote for me: [[LINK href=""]][[/LINK]].

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


mrking comments:

Yup, already did.


petrisor Daniel answers:

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