• Hello,

    New to wordpress and PHP.

    How do I wrap this shortcode around some HTML/PHP? I’ve tried using the do_shortcode but that didn’t work.

    <?php echo do_shortcode( [timed-content-rule id="101"] ) ?> 
    
    <?php echo do_shortcode( [/timed-content-rule] ) ?>

    PHP/HTML

    <?php
    $rows = get_field('breakfast');
    $row_count = count($rows);
    $i = rand(0, $row_count - 1);
    
    ?>
    
    <h1>
        <?php echo $rows[ $i ]['dish_name']; ?>
    </h1>
    <p>
       <?php echo $rows[ $i ]['dish_description'];  ?>
    </p>
    <h3>
        Served<span><?php echo $rows[ $i ]['time_served'];  ?></span>
    </h3>

    https://wordpress.org/plugins/timed-content/

Viewing 1 replies (of 1 total)
  • Plugin Contributor K. Tough

    (@kjvtough)

    Hi.

    Put the content you want to protect into a variable, then wrap everything into a do_shortcode() call. It’ll look something like this:

    <?php
    $rows = get_field('breakfast');
    $row_count = count($rows);
    $i = rand(0, $row_count - 1);
    
    $my_timed_content = "<h1>" . $rows[$i]['dish_name'] . "</h1>";
    $my_timed_content .= "<p>" . $rows[$i]['dish_description'] . "</p>";
    $my_timed_content .= "<h3>Served<span>" . $rows[$i]['time_served'] . "</span></h3>";
    echo do_shortcode( '[timed-content-rule id="101"]' . $my_timed_content . '[/timed-content-rule]' );
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Use Shortcode inside Template’ is closed to new replies.