简体   繁体   中英

Insert PHP code in shortcode using do_shortcode()

I am trying to insert PHP code in a shortcode.

For now it look likes this:

    <?php echo do_shortcode('[to_like][/to_like]'); ?>

<?php do_action('single_spot_after_content', get_the_ID(), 'after_content'); ?>

I have tried several plugins to combine this to one shortcode (PHP shortcode plugin, Advanced Custom fields, etc.)

This is what I want to accomplish, but it is not working:

<?php echo do_shortcode('[to_like]<?php do_action('single_spot_after_content', get_the_ID(), 'after_content'); ?>
[/to_like]'); ?>

In the front-end the user can select the value through a dropdown field --> for example 10% discount (this is going to be displayed when a visitor likes the box). The theme has a special markup field (you can create custom submission fields) where %% is going to be changed by the chosen value from the customer. This value is going to be displayed on the website (singe listing page).

How can I implement this? This is so vital for the website.

尝试这个:

<?php echo do_shortcode( '[to_like]' . do_action('single_spot_after_content', get_the_ID(), 'after_content') . '[/to_like]' ); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM