• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED How to use 2 snippets?

Messages
3
Likes
0
Points
1
#1
I have 2 snippets:

Snippet 'A' that defines some useful php functions specific to my website
Snippet 'B' php code that makes use of those functions

I tried to use
[wbcr_php_snippet id="id_of_A"]
[wbcr_php_snippet id="id_of_B"]

But it didn't work (it broke my page). If I just merge 'A' into 'B' so there is just one snippet, it works correctly

Is there any reason why this does not work? Is there a way to 'include' one snippet into another?

Thanks
 

Temyk

Support team
Staff member
Messages
356
Likes
20
Points
18
#2
Hi,

In our plugin this will not work, because the code of each snippet is executed separately. But it will work:
[wbcr_php_snippet id="A"]:
PHP:
function myfunc()
{
    echo "OK";
}
[wbcr_php_snippet id="B"]:
PHP:
do_shortcode('[wbcr_php_snippet id="A"]');
myfunc();
 

alexkovalev

Program developer
Staff member
Messages
231
Likes
17
Points
18
#3
Snippet 1: Run Everywhere
---
PHP:
function myfunc()
{
    return "OK";
}
function test() {
   return 1+1;
}
Snippet 2: Where there is a shortcode
---
PHP:
if( function_exist('myfunc') ) {
    echo myfunc();
}
---------------------

The second snippet is already used in the article, as a shortcode.

Best regards, Alex