Insert PHP code into the Visual Composer

Morgari picture Morgari · Nov 16, 2016 · Viewed 14.6k times · Source

I have the php code (ACF Pro plugin code). How can I insert this code into my Visual Composer? Can't find the solution for a long time but now it's critical for me.

<?php if( have_rows('add_a_new_table') ): ?>
    <?php 
    while( have_rows('add_a_new_table') ): 
        the_row(); 
        // vars
        $t_title         = get_sub_field('t_title');
        $t_pricing       = get_sub_field('t_pricing');
        $t_emails_number = get_sub_field('t_emails_number');
    ?>       
        <div class="col-sm-12 col-sm-4 text-center">
            <div class="courses-column">      
                <div class="courses-column-inner">
                    <h3><?php echo $t_title; ?></h3>
                    <p style="font-size: 24px;">
                        <?php echo $t_pricing; ?>
                    </p>
                    <br>
                    <p style="font-size: 16px;">
                        <?php echo $t_emails_number; ?>    
                    </p>
                </div>
            </div>
        </div>

    <?php endwhile; ?>
<?php endif; ?> 

I can't realize it via shortcodes because of if & while conditions. Row HTML and Row JS are useless for me as well.

Answer

Chinou picture Chinou · Nov 16, 2016

Just put your php code inside a function and create shortcode

function vComp(){
**PHP CODE**
 }
add_shortcode( 'vShortcode', 'vComp' );

Goto Visual Composer- Shortcode Mapper - Map Shortcode - then Enter valid shortcode (Example: [vShortcode]).