WordPress.org

Forums

Adding a css class to the linked images (2 posts)

  1. Ameisenman
    Member
    Posted 4 years ago #

    Hi,
    I want to add the fancybox effect to all images inside a post which are linking to the original image. For this purpose I need to add the css-class property to the surrounding <a>-Tag of the image. How can I do this?

    So far I came to a result:

    function addFancybox($content)
    {
    if (preg_match_all('/<a.*?><img.*?<\/a>/',$content,$matches))
    {
    print_r($matches);
    }
    }
    add_filter( "the_content", "fancyfilter" );

    But how to continue???

    Thanx in advance!!!

  2. WayLay Design
    Blocked
    Posted 4 years ago #

    Check out this link: http://www.island94.org/2011/01/adding-class-to-wordpress-linked-images

    Works beautifully, and if you're using "rel" instead, just replace all instances of "class" with "rel" and it's good to go!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.