Skip to content
Advertisement

Globally add code snippet to WordPress PDF links using functions.php

Using functions.php in WordPress, how do I identify all links that contain .pdf (all links to PDF files), ignoring links to other types of files, and then add a bit of code to the element? For example:

BEFORE

JavaScript

AFTER

JavaScript

The added code will be identical for all links. I assume I need some sort of variation on this function:

JavaScript

I based that function on another function I am using which removes HEIGHT and WIDTH parameters from WordPress elements.

Advertisement

Answer

I would use javascript or jQuery for this as you are using JS anyway.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement