0

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply. I tried as above but it is now displaying title on the page and not gets appended to the anchor tag...
Actually the issue is with the_title. When I give some other field of post. it works well... Thankyou so much
Running do_shortcode() is an option for this use case, but not in general. People will most likely want to prepend/append code to shortcodes that are included in plugins or themes. This solution is not relevant in the majority of cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.