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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.