Insert shortcode inside plugin code

Posted in: Newspaper
Post count: 26

I have a particular plugin that inserts a video iframe. I want to insert right before this iframe an advertisement, but with the theme shortcode.

Here’s the relevant line from the plugin’s code:
$videoiframe = ‘HERE I WANT TO INSERT THE SHORTCODE<script type=\’text/javascript\’> … HERE GOES SOME MORE HTML CODE…

I want to insert the following shortcode, but when I put it in the place I specified above I receive ‘fatal error’.
<?php echo do_shortcode(‘[td_ad_box spot_id=”custom_ad_1″]’); ?>

I don’t know how to insert it correctly.

Can you help?

Post count: 26

Okay I succeed to insert the shortcode without receiving fatal error by adding slashes before the apostrophe signs like this:
$videoiframe = ‘<?php echo do_shortcode(\'[td_ad_box spot_id=”custom_ad_1″]\’); ?><script type=\’text/javascript\’>………

But the ad is still not shown

When I check the source code it’s shown like this: http://i.imgur.com/JdYwFzb.png

It didn’t translate the PHP code to HTML code. Why?

  • This reply was modified 11 years by idansx.
  • This reply was modified 11 years by idansx.
Post count: 6600

Hi,

If you put the php code between apostrophes like this: http://screencast.com/t/JuxaG3bp it will be interpreted as a string and the output it will be parsed like it is not rendering the code.

Try to concatenate the script and the rest of the html after the do_shortcode function, it should look something like this: http://screencast.com/t/au5wceeOH – while you declare a variable you don’t need to php tags anymore as you are already in php language.

If you still have issues with this and can’t manage to do it we suggest you get a freelancer to do it for you as you need custom work for this.

Thanks

Post count: 26

I already solved it. I made a new variable $advertisement and inserted the do_shortcode into this variable.
Then concatenated it like this $advertisement . $videoiframe
It’s the same as you said 🙂

Thank you

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.