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:
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');
});
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
✨ You can now install ACF PRO with Composer, eliminating the need for third-party installers. Get the details and instructions here. https://t.co/ebEfp60Pwj
— Advanced Custom Fields (@wp_acf) February 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.