最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How do I wrap this?

programmeradmin0浏览0评论

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]

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论