Support » Fixing WordPress » Shortcode use in php echo section

  • Resolved andyharvey661

    (@andyharvey661)


    Hi

    Any help gratefully received, I’d like to use the shortcode [cm_ad_changer campaign_id="1"] in a echo section in my header.php file.

    I’ve tried all sorts of combinations but can’t get it to work
    <?php echo do_shortcode(‘[cm_ad_changer campaign_id=”1″]’); ?>
    ‘<?php echo do_shortcode(‘[cm_ad_changer campaign_id=”1″]’); ?>’
    <?php echo do_shortcode(“[cm_ad_changer campaign_id=”1″]”); ?>
    ‘echo do_shortcode(‘[cm_ad_changer campaign_id=”1″]’)’;

    Here is the code snippet with the shortcode insertion attempt.

    if ( is_home() or is_front_page()) {echo '<div class="section group">
    				<div class="col span_1_of_2">
                        <a href="http://www.ptmagazine.co.uk/testsite/"><img src="http://www.ptmagazine.co.uk/testsite/wp-content/uploads/2013/12/PT-Magazine-Web-Logo.jpg"></a>
    				</div>
    				<div class="col span_1_of_2">
                                       '<?php echo do_shortcode("[cm_ad_changer campaign_id="1"]");?>'
    				</div>
    			</div>
    </div>
    </div>' ; }

    Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Anonymous User 7658014

    (@anonymized_7658014)

    <?php if ( is_home() or is_front_page()) : ?>
    	<div class="section group">
    		<div class="col span_1_of_2">
    			<a href="http://www.ptmagazine.co.uk/testsite/"><img src="http://www.ptmagazine.co.uk/testsite/wp-content/uploads/2013/12/PT-Magazine-Web-Logo.jpg"></a>
    		</div>
    		<div class="col span_1_of_2">
    			<?php echo do_shortcode( '[cm_ad_changer campaign_id="1"]' ); ?>
    		</div>
    	</div>
    </div>
    </div>
    <?php endif; ?>
    Anonymous User 7658014

    (@anonymized_7658014)

    If you want the echo, you would need to chain the strings like:

    <?php if ( is_home() or is_front_page()) {
    	echo '<div>' . do_shortcode( '[cm_ad_changer campaign_id="1"]' ) . '</div>';
    }
    Thread Starter andyharvey661

    (@andyharvey661)

    Awesome, thanks very much Caspar the below code works a treat.

    <?php
    if ( is_home() or is_front_page()) {echo '<div class="section group">
    				<div class="col span_1_of_2">
                        <a href="http://www.ptmagazine.co.uk/testsite/"><img src="http://www.ptmagazine.co.uk/testsite/wp-content/uploads/2013/12/PT-Magazine-Web-Logo.jpg"></a>
    				</div>
    				<div class="col span_1_of_2">
                                       ' . do_shortcode( '[cm_ad_changer campaign_id="1"]' ) . '
    				</div>
    			</div>
    </div>
    </div>' ; } ?>
    Anonymous User 7658014

    (@anonymized_7658014)

    Glad it does, have fun!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Shortcode use in php echo section’ is closed to new replies.