Hello,
I have this custom function
function changeAncreToLink($content){
$all_ancres = preg_match_all("/(?<=\[).*?http.*?(?=\])/",$content,$matches);
if(!empty($matches)){
$matches = $matches[0];
foreach ($matches as $match) {
$match = str_replace("->", "->", $match);
$sub_match = preg_split("/->/",$match);
$ancres = preg_split('/\[/', $sub_match[0]);
$ancre = $ancres[count($ancres)-1];
$link = '<a href="'.$sub_match[1].'">'.$ancre.'</a>';
$content = str_replace("[$ancre->".$sub_match[1]."]", $link, $content);
$content = str_replace("[$ancre->".$sub_match[1]."]", $link, $content);
}
}
return $content;
}
add_filter( 'the_content', 'changeAncreToLink' );
that replaces
by
<a href="string2">string1</a>
It works great on another site, but it seems it's being conflicting with Toolset Views.
Could you please confirm there is a conflict and how to solve it ?
Thank you.
We cannot give assistance with Custom Code of this kind.
What I can do is help with the Toolset related part of the logic
When working with Views, we have to keep in mind that Views displays its contents thru the the_content filters of WordPress.
So for example, a Content Template would display only if the_content is used by the theme, and then it substitutes that content with the things you add to the Content Template.
A View on the other hand, of course, is "just" a shortcode that will not replace the whole the_content but it still works with that filter too, so for example when you have a Loop Item Template, that is like having a the_content call ongoing.
Now, I am not sure how your code "conflicts" with Toolset, but knowing more about what you expect and what happens instead, might help me to further help you pinpoint the issue.
The function is meant to "translate" an other CMS shortcode :
[my link anchor-><em><u>hidden link</u></em>;
into a proper HTML code.
But I think I finally found out what
was meant to ! Setting it to "false" solved the problem.
Thank you.
Yes, precisely, the suppress_filters attribute, when inserting a Content Template, will avoid any filter on the_content in this template.
Note that this can't be set when you directly assign the template to a post, only when you insert the Template as a ShortCode.
Thanks for sharing the solution!