Skip Navigation

[Resolved] Custom function with the_content and toolset

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Beda 4 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#1581353

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

[string1->string2]

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.

#1581899

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.

#1582037

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

suppress_filters=""

was meant to ! Setting it to "false" solved the problem.
Thank you.

#1582151

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!