Support

Account

Home Forums General Issues Add class to linked image anchor in WYSWIYG-Field Reply To: Add class to linked image anchor in WYSWIYG-Field

  • You could try using a plugin to add a custom permalink base URL for media files, such as this one:

    Attachment Slug

    Then target the different link types purely with CSS:

    .post-content a { /* any link or custom link */ }
    .post-content a[href*="/media_base_url/"] { /* overrides for attachment links */ }
    .post-content a[href*="/wp-content/uploads/"] { /* overrides for direct media links */ }

    The only problem is with custom links, which are not targetable by themselves. In this case, you could use some JavaScript:

    jQuery( function() {
    jQuery('.post-content a > img').parent().addClass('media-link');
    });