-3

I've been trying to link a custom CSS style-sheet in my Magento theme, but it's not applying the CSS and I'm getting an error in the Chrome Console with a Syntax error: Unexpected * ..? I guess it's misinterpreting the CSS for a JS file but I don't know why.

Here is my code:

 <script type="text/javascript" src="<?php echo 
 $this->getSkinUrl('css/custom.css') ?>"</script>
1

3 Answers 3

3

If you want to use it for one time in a .PHP file simply use:

<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('customstyle.css') ?>" />

And BTW: Don't use a script tag for a stylesheet.

If you want to use the stylesheet a lot more. Then you have to make a block in your layout.xml

Sign up to request clarification or add additional context in comments.

2 Comments

A derp my bad, didn't even see it. It was sepose to be a <link> tag ofcourse.
If this helped you please mark my answer as best :D
0

You need to add it in your themes 'page.xml', which should be here;

MAGE ROOT /app/design/frontend/XXX/YYY/layout/page.xml

Where XXX/YYY are the path to your theme.

Within this file, find this block;

<block type="page/html_head" name="head" as="head">

And add your css like this;

<action method="addCss"><stylesheet>css/custom.css</stylesheet></action>

Refresh your cache afterwards - including the css/js cache if you have merge enabled.

2 Comments

I'm kind of a Magento newbie but it seems to work fine in the head.phtml. Why should i add the custom CSS in the page.xml? I'm not trying to start a fight or something, i want to get to know Magento better and learn from this.
hi no problem , this is just the standard way to add css/js to your magento themes. This way you can also exclude them from certain pages if you need to.
0

remove (script) tag from the code.

<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('custom.css') ?>" />

1 Comment

@Thijs Kempers-from where i copied ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.