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?

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.