1
votes

I'm trying to created a custom shortcode in wordpress but I can't get it working.

Here's the code I have so far:

function wp_test_video($atts) {
     extract(shortcode_atts(array(

          'X' => ''
          'Y' => ''

     ), $atts));

    return '[iframe src="http://www.example.com/test.php?X='.$atts['X'].'&Y='.$atts['Y'].'"]';
}



add_shortcode('test', 'wp_test_video');

Everytime I try and insert it into my functions.php file my site just breaks.

EDIT: The shortcode is now working but it seems to be acting differently from the same code inserted without the shortcode.

Here is an image of the compiled code from the shortcode in a post by itself:

http://i.imgur.com/4lM8jC5.jpg

Here is what a post looks like when using the shortcode to generate the same code:

http://i.imgur.com/gxk6k3C.jpg

The video is embedding but it's breaking out of the article wrapper causing none of widgets or comments to work (also appears to mess up the search bar at the top).

1
Are you getting a stack trace or an error? - Shawn Mehan
The site refreshes into a blank page and doesn't come back until I replace the functions.php file back to default. - d.reid.nz
Than take a look into your php error log and turn on the wp_debug mode in the wp-config.php. Please post the error. - cgee
I installed it by turning it into a plugin and it threw this error: Parse error: syntax error, unexpected ''fps'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /home3/digitalm/public_html/wp-content/plugins/morgue-shortcode.php on line 16. So I removed the 2nd array 'Y', and it works perfectly. Is there another way to create a custom shortcode with 2 stored values? - d.reid.nz

1 Answers

0
votes

You forgot a comma after your first item in your array and forgot to assign the shortcode_atts to a variable. Don't use extract(), it's deprecated.

function wp_test_video($atts) {

  $atts = shortcode_atts(
    array(
      'X' => '', // <-- This one
      'Y' => ''
    ),
  $atts);

  return '[iframe src="http://www.example.com/test.php?X='.$atts['X'].'&Y='.$atts['Y'].'"]';
}