Archived topic
Elements
4 replies · Started by Marco on March 6, 2019
Hello
tried to create a hook element with the following code but I'm getting some errors - hope somebody can help.
Thanks
<?php
global $post;
$pid = (int) $post->post_parent;
echo do_shortcode('[ gallery id="'.$pid.'" numberposts="3" ]');
?>
the error is as follows: Parse error: syntax error, unexpected 'gallery' (T_STRING), expecting ',' or ')' in /Users/Marco/Sites/cms/wp-mmjaeger/wp-content/plugins/generatepress-premium/elements/class-hooks.php(180) : eval()'d code on line 10
Hi there,
I just gave your code a try and didn't get that error. Just to confirm, is "Execute PHP" checked?
Execute PHP is checked - I've added the same element to the site online - gave you the url and credentials some days ago - same error?! maybe I'm doing something wrong?
Parse error: syntax error, unexpected 'gallery' (T_STRING), expecting ',' or ')' in /home/mmjaeger/public_html/gp/wp-content/plugins/generatepress-premium/elements/class-hooks.php(180) : eval()'d code on line 7
I put basically the same code into the functions.php file and it works fine?
What about this?:
<?php
global $post;
$pid = (int) $post->post_parent;
$shortcode = '[ gallery id="' . $pid . '" numberposts="3"]';
echo do_shortcode( $shortcode );
?>
Be sure to remove the space between the [ and gallery. I had to add the space to prevent our site from trying to render the shortcode.