Nida
Nida

Reputation: 1702

how to append php code in the shortcode in wordpress

I am using the shortcode in the loop inside template file and also using the lightbox form plugin.

<?php query_posts('showposts=9&post_type=packages') ?>
<?php while (have_posts()) :the_post(); ?>
  <?php echo the_post_thumbnail(); ?>          
   ...
    ...
    <?php echo do_shortcode("[formlightbox text='Book Now' title=the_title][contact-form-7      id='383' title='Booking Form'][/formlightbox]"); ?>

 <?php endwhile; ?>

Please note that in the shorcode there is title=the_title and it is not appened to the anchor tag. But when I use title='hello'or something else it gets appended to the anchor tag. I want current post's title should get appened to the rendered anchor tag via shortcode.

please help me

Upvotes: 0

Views: 1267

Answers (1)

Jared
Jared

Reputation: 12524

Break the string and use the string concatenation operator to combine the function into your string.

 <?php echo do_shortcode("[formlightbox text='Book Now' title='" . get_the_title() . "'][contact-form-7      id='383' title='Booking Form'][/formlightbox]"); ?>

Update This should use the get_the_title() as opposed to the_title() which echos the title.

Upvotes: 3

Related Questions