Skip to content

Instantly share code, notes, and snippets.

@themeblvd
Created March 24, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themeblvd/a5ce013cfd142af3e3e5db52e43368b6 to your computer and use it in GitHub Desktop.
Save themeblvd/a5ce013cfd142af3e3e5db52e43368b6 to your computer and use it in GitHub Desktop.
<?php
// First, let's just build a string of content.
// Method 1: If you using single quotes and you want to insert
// variables, you MUST open and close the string, and append chunks
// together with periods.
$str = '[lightbox link="' . $videourl . '" thumb="' . $videothumb . '"]';
// Method 2: When wrapping the string in double quotes, you can actually
// insert variables directly into the string. But you need to make
// sure and escape your double quotes within with a backslash.
$str = "[lightbox link=\"$videourl\" thumb=\"$videothumb\"]";
// Method 3: Both options above can look a little messy when you look
// back at them later. This why I really like to use PHP's sprintf()
// function, to make the code look a bit cleaner and give a more clear
// visual of what's happenning.
$str = sprintf(
'[lightbox link="%s" thumb="%s"]',
$videourl,
$videothumb
);
// And then just pass your string to the do_shortcode() function
// and echo it out.
echo do_shortcode( $str );
// And of course, you could build the string with any of the methods
// above directly within the do_shortcode() call, too.
echo do_shortcode( '[lightbox link="' . $videourl . '" thumb="' . $videothumb . '"]' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment