• 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

Developer & Support
Messages
1,129
Likes
42
Points
48
#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
267
Likes
19
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