pfff…sorry still some test code…
Now I tested it exactly the way you want to implement it. And this works on my local WP installation:
function external_link_filter($created_link, $original_link, $label, $attrs = array()) {
if (isset($attrs['class']) && strpos($attrs['class'], 'gajnfads') !== false) {
return $original_link;
}
return $created_link;
}
add_filter('wpel_external_link', 'external_link_filter', 10, 4);
Thread Starter
Martin
(@rastarr)
Absolutely BRILLIANT!
A few tweaks to the OIO-Publisher plugin and now your plugin’s enhancement has the links working perfectly.
Thank you so much for a brilliant plugin! Rated 5 Stars
This is the second support topic I’ve posted in for WP External Links, and the second time I’ve been really impressed by @freelancephp responses! 🙂
I’ll post my problem/solution here just in case it saves someone else the 2hrs I’ve spent on this today.
My problem:
==========
WP External Links produces strange mangled output of <a> tags that contain custom HTML5 attributes.
For example:
<a href="http://example.com" data-referer="something.com">External Link</a>
will get output as:
<a class="ext-link ext-icon-6" href="http://example.com" rel="external nofollow" 0="data-referer="something.com"">External Link</a>
I’m guessing this is because when the regex rebuilds the <a> tag, it doesn’t recognize the data-* attributes, so creates an array of them.. hence the extra 0=… 1=…. 2=…. etc.
My solution:
=============
Using the new & excellent wpel_external_link() filter hook, it’s easy to exclude this links from being processed.
However it would be perfect if the rebuilding function could account for these custom attributes and preserve them… but I don’t know the level-of-effort required for this. 😛
I have tried that code with class name “sfx” for http://www.peleke.de/galerie/flickr/?page_id=0&albid=72157633109872572 but that doesn’t seem to work.
Can you please take a look why?
Thanks!
Hello!
I tried to use the hook to exclude a class “not-external” and place this code into functions.php
function external_link_filter($created_link, $original_link, $label, $attrs = array()) {
if (isset($attrs['class']) && strpos($attrs['class'], 'not-external') !== false) {
return $original_link;
}
return $created_link;
}
add_filter('wpel_external_link', 'external_link_filter', 10, 4);
my link is a kind of
<a href="http://fc00.deviantart.net/fs70/i/2013/220/4/2/horo_by_mrshlapa-d6h90v5.png" class="not-external"> 12313213</a>
But is doesn’t seem to work. I don’t know what’s wrong. Please, any help