chris86 Posted September 17, 2006 Share Posted September 17, 2006 I'm getting a syntax error (on line 15) when I insert the following code into a custom.php file. [code]function random_scheme(){$schemes = glob(TEMPLATEPATH . '/skins/light-gold/schemes/*.css');if ( $schemes ){$key = array_rand($schemes);$scheme = basename($schemes[$key]);?><link rel="stylesheet" type="text/css"href="<?php echo get_template_directory_uri() . '/skins/light-gold/schemes/' . $scheme; ?>"/><?php//The bracket below is line 15.}} # end random_scheme()add_action('wp_head', 'random_scheme', 50);[/code][b]Here's the syntax error I'm getting...[/b]Parse error: syntax error, unexpected '}' in /home/username/public_html/domain_name/blog/wp-content/themes/semiologic/skins/light-gold/custom.php on line 15I was given this code by someone else who says nothing's wrong with the code. But, according to the syntax error, it looks like there's a problem with brackets. He's got 2 closing brackets in a row. That can't be right..? How do I get rid of the syntax error? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 17, 2006 Share Posted September 17, 2006 He's right. There are two loops, so there needs to be two loop closings. If you indent the code to show the structure, it's easier to follow:[code]function random_scheme(){ $schemes = glob(TEMPLATEPATH . '/skins/light-gold/schemes/*.css'); if ( $schemes ){ $key = array_rand($schemes); $scheme = basename($schemes[$key]);?><link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri() . '/skins/light-gold/schemes/' . $scheme; ?>"/><?php }} # end random_scheme()add_action('wp_head', 'random_scheme', 50);[/code] Quote Link to comment Share on other sites More sharing options...
chris86 Posted September 17, 2006 Author Share Posted September 17, 2006 Thanks Andy. Good to know his code is correct. Although, it still leaves me hanging. If the code is technically correct, why am I getting a syntax error on line 15? How can this be? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 17, 2006 Share Posted September 17, 2006 The php interpreter's error message explains what line it was at when it found a condition it could not handle (for the stated reason). The origin of the error might well have been, and sometime is, many lines before the reported line. That code in isolation runs without error. What's happening before it? Is it perhaps an included file and the source of the error is in the code that included it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.