[Resolved] Mixing shortcodes and PHP in a hook element

Home Forums Support [Resolved] Mixing shortcodes and PHP in a hook element

Home Forums Support Mixing shortcodes and PHP in a hook element

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2157236
    Ian

    I have the following snippet in a hook element, and the Execute Shortcodes/PHP are both checked. But the PHP does not appear to be executed before the shortcode. Is there anything I should consider?

    [pdfjs-viewer url="<?php the_field( 'pdf' ); ?>" attachment_id="<?php echo attachment_url_to_postid( get_field( 'pdf' ) ); ?>" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true]

    #2157253
    Leo
    Staff
    Customer Support

    Hi Ian,

    I’m not sure unfortunately – the hook element shouldn’t be the issue here as it simply display whatever you are adding and doesn’t have the ability to make something work or not work.

    Does the code work in a normal page editor?

    #2162666
    Ian

    For whatever reason, it seems that the PHP is not being executed inside the shortcode. I was able to resolve this using the WordPress PHP function: <?php echo do_shortcode("[shortcode]"); ?> resulting in something like this, which does work:

    <?php $pdf = get_field( 'pdf' ); ?>
    <li>URL: <?php echo esc_url( $pdf['url'] ) ?></li>
    <li>ID: <?php echo esc_html( $pdf['id'] ) ?></li>
    <?php $pdfshort="[pdfjs-viewer url=\""  . esc_url( $pdf['url']) . "\" attachment_id=\"" . esc_html( $pdf['id']) . "\" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true]" ?>
    <li>PDF: <?php echo $pdfshort ?></li>
    Embed:
    <?php echo do_shortcode("$pdfshort"); ?>

    Note the use of \” to escape the quotes in the shortcode; using &quot; did not work.

    #2162772
    Leo
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.