0

Hey I am trying to add a customize option in a wordpress theme that allows for the user to upload there own image in in a showcase but im getting a syntax error in my customize.php file. Can any one help me write this the correct way? thanks!

Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/themes/wpbootstrap/inc/customizer.php on line 13

        $wp_customize->add_setting('showcase_image', array(

        'default' => get_bloginfo('template_directory').'/img/showcase.jpg', 'wpbootstrap'),
    line 13 'type' => 'theme_mod'
        ));
Steven Grier
  • 31
  • 2
  • 4
  • So what is `'type' => 'theme_mod'`? – zerkms Aug 11 '17 at 00:45
  • 1
    @community, please let the OP spot the problem themselves. Teach them how to debug, not just provide a ready copy-paste answer. – zerkms Aug 11 '17 at 00:46
  • I'm not sure what 'type' => 'theme_mod' does yet, I'm following a tutorial and I wrote it exactly like he does but I'm getting a syntax error – Steven Grier Aug 11 '17 at 00:56
  • 1
    "I'm following a tutorial and I wrote it exactly like he does " --- so the lesson here: don't blindly follow tutorial, make sure you completely understand **every** thing before you put in your code. Otherwise, as you may have noticed - you won't be capable of doing anything by yourself. – zerkms Aug 11 '17 at 00:58
  • `$x = array('type' => 'theme')` sets a mapped key to a value in an array. Which means `if ($x['type'] == 'theme') { echo 'YES!' }` is true. It only makes sense inside arrays (hint, hint) – BareNakedCoder Aug 11 '17 at 00:59
  • Got it! I had an extra ")" which put my value outside the array. Thanks for all your help I'm new to coding and still have a lot to learn but I'm thankful for such a supporting community. – Steven Grier Aug 11 '17 at 01:38

1 Answers1

3

Without spoon feeding the answer (as requested to @community above), but giving a re-usable technique to find these types of bugs ...

Temporarily reformat your code so all function paramters and/or array elements are on their own line and using identing appropriately. Eventually you'll likely see something that is not what you intended. Example below (you're almost there).

$wp_customize->add_setting(
    'showcase_image',    // func parm
    array(   
        'default' => get_bloginfo(
                'template_directory'
            ).'/img/showcase.jpg',
        'wpbootstrap'
    ),
    'type' => 'theme_mod'
)
);
BareNakedCoder
  • 3,257
  • 2
  • 13
  • 16
  • I do like emphasizing on importance of the proper indentation :-) – zerkms Aug 11 '17 at 00:54
  • 2
    I think it's hard to properly indent extra closing braces. But you did a good job hiding it. – jh1711 Aug 11 '17 at 01:02
  • @jh1711, good point. I kinda stopped when I saw something bad. I've updated the code above to show extra closing parenthesis a little better. – BareNakedCoder Aug 11 '17 at 01:04
  • Thank you your technique helped me figure out I had an extra ")" – Steven Grier Aug 11 '17 at 01:39
  • 1
    @Steven Grier, you're welcome. As a courtesy to those who answer your questions, you should mark the answer as "correct". That gives that person a few more StackOverflow points as a small reward for their efforts. – BareNakedCoder Aug 11 '17 at 19:47