php - How do I wrap this?

I have snipped of PHP code I'd like to have wrapped within its php-file with the do_shortcode function. Unfortunatl

I have snipped of PHP code I'd like to have wrapped within its php-file with the do_shortcode function. Unfortunatly, I don't have clue how to do this. Several ways I tried end in an error on the page.

This is the code snipped I'd like to wrap:

<?php echo the_aiovg_player( $attributes['id'] ); ?>

And this is the wrapping shortcode that should cover it:

[pc-pvt-content allow="all" block="" warning="1" message="1" login_lb="" registr_lb=""][/pc-pvt-content]

So at the end it should look like this:

[pc-pvt-content allow="all" block="" warning="1" message="1" login_lb="" registr_lb=""]<?php echo the_aiovg_player( $attributes['id'] ); ?>[/pc-pvt-content]

How can I implement it in my php-code that it works?

I have snipped of PHP code I'd like to have wrapped within its php-file with the do_shortcode function. Unfortunatly, I don't have clue how to do this. Several ways I tried end in an error on the page.

This is the code snipped I'd like to wrap:

<?php echo the_aiovg_player( $attributes['id'] ); ?>

And this is the wrapping shortcode that should cover it:

[pc-pvt-content allow="all" block="" warning="1" message="1" login_lb="" registr_lb=""][/pc-pvt-content]

So at the end it should look like this:

[pc-pvt-content allow="all" block="" warning="1" message="1" login_lb="" registr_lb=""]<?php echo the_aiovg_player( $attributes['id'] ); ?>[/pc-pvt-content]

How can I implement it in my php-code that it works?

Share Improve this question asked Apr 18, 2019 at 7:06 EffectionEffection 1
Add a comment  | 

1 Answer 1

Reset to default 0

If pc-pvt-content supports nested shortcodes, then I think you could wrap the_aiovg_player() inside a custom shortcode. Something like this,

// In your theme functions.php
if ( ! shortcode_exists( 'the_aiovg_player' ) && function_exists( 'the_aiovg_player' ) ) {
  function myprefix_the_aiovg_player_shortocode( $atts ) {
    $id = ( ! empty( $atts['id'] ) && is_numeric( $atts['id'] ) ) ? intval( $atts['id'] ): 0;
    if ( ! $id ) {
      return '';
    }
    return the_aiovg_player( $id );
  }
  add_shortcode( 'the_aiovg_player', 'myprefix_the_aiovg_player_shortocode' );
}

Then you could use the custom shortcode like this,

[pc-pvt-content ..attributes.. ][the_aiovg_player id="123"][/pc-pvt-content]

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745575551a4633940.html

相关推荐

  • php - How do I wrap this?

    I have snipped of PHP code I'd like to have wrapped within its php-file with the do_shortcode function. Unfortunatl

    15小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信