Jump to content

Syntax error


chris86

Recommended Posts

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 15

I 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? 
Link to comment
https://forums.phpfreaks.com/topic/21039-syntax-error/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/21039-syntax-error/#findComment-93394
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/21039-syntax-error/#findComment-93400
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.