• Hello, I have been trying for days now to link my CSS page into my wordpress page.

    They are hosted locally on my computer via MAMP. I am trying to build a custom theme at the minute and

    This is the error code I get via the chrome developer console:
    Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    I have tried several different methods to get the CSS to link but it won’t work. I don’t know if it has anything to do with the PHP Configuration but MAMP suggests the PHP config is fine.

    Here are my files. (Excuse the file names, I was following a youtube tutorial.)

    style.css files
    /*
    Theme Name: Awesome Theme
    Author: Adam
    Version: 0.0.6
    Description: This is an awesome theme
    Tags: Testing, Sample, Please work
    Licence: GNU General Public License v2 or later
    /*

    Background {
    color: blue;
    }

    functions.php file
    <?php

    function awesome_script_enqueue() {

    wp_enqueue_style(‘customstyle’ , get_template_directory_uri() , ‘/css/awesome.css’ , array(), ‘0.0.6’ , ‘all’);
    wp_enqueue_script(‘customjs’, get_template_directory_uri() , ‘/js/awesome.js’ ,array(), ‘0.0.6’, true);
    }

    add_action(‘wp_enqueue_scripts’, ‘awesome_script_enqueue’)
    ?>

    awesome.css file
    html,
    body {
    margin: 0;
    color: blue;
    background: grey;
    font: sans-serif;

    }

    body {
    padding: 20px;
    }

    index.php

    <?php get_header(); ?>
    <h1> This is my index </h1>
    <?php get_footer(); ?>

    footer.php

    <footer>
    <p> This is my footer </p>
    </footer>
    </body>
    </html>

    <b> header.php</B
    <!doctype html>
    <html>
    <head>
    <meta charset=”utf-8″>
    <title> Awesome Theme </title>
    <?php wp_head(); ?>
    </head>
    <header> This is my header</header>

    <body>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter adamr100

    (@adamr100)

    It’s driving me insane and I cannot work out why. I am open to advice/feedback if there is a better option to use for a website wide css file.

    First off ditch MAMP, you are on a MAC, USE IT
    https://mallinson.ca/osx-web-development/

    Second, your code is a bit incorrect

    
    function awesome_script_enqueue() {
    
    wp_enqueue_style(‘customstyle’ , get_template_directory_uri() , ‘/css/awesome.css’ , array(), ‘0.0.6’ , ‘all’);
    wp_enqueue_script(‘customjs’, get_template_directory_uri() , ‘/js/awesome.js’ ,array(), ‘0.0.6’, true);
    }
    
    add_action(‘wp_enqueue_scripts’, ‘awesome_script_enqueue’)
    

    You used commas and in php a . (period) concatenates strings.
    AND you set an empty array… Does your script depend on jQuery or is it Vanilla JS? If it needs jQuery it should be array(‘jquery’)
    https://developer.wordpress.org/reference/functions/wp_enqueue_script/
    There is no array in the css call though.
    True and False are for version and place in footer

    try this:

    
    wp_enqueue_style(‘customstyle’ , get_template_directory_uri() . ‘/css/awesome.css’ , false, '0.0.6');
    
    
    wp_enqueue_script(‘customjs’, get_template_directory_uri() . ‘/js/awesome.js’ ,array('jquery), ‘0.0.6’, true);
    
    Thread Starter adamr100

    (@adamr100)

    Hello, thanks for your detailed reply.

    I have currently made several steps backwards I think…

    I followed the instructions on your link to install SQL etc and when I access ‘localhosts’ all I get is ‘it works’.

    I have followed several threads to point this page to my sites location for it to load my page but no matter what it just says ‘it works’

    Thank you.

    There are a few other steps you need to do detailed in that tutorial to get everything set up perfectly. Follow it all the way to the suggestions section and install everything required. Makes web dev SO much easier. I deleted MAMP Pro years ago.

    On my Mac, I jet create a new WordPress install in my WWW folder and type folderName.dev into the address bar and it loads up the site.

    Did you get the script and CSS to enqueue correctly? You can still use MAMP until you have everything set up in OSX –

    Thread Starter adamr100

    (@adamr100)

    I think I have made some progress but now whenever I type in localhost I get a page full of PHP information. WHich isn’s in my ‘site’ directory.

    I don’t know if I have a messy repository of installs etc now and that might be the reason. Is there a way to remove apache, php, homebrew etc in totality and start agaib?

    THe script and the CSS didnt enqueue correctly no.

    If you followed the tutorial correctly and installed everything you should just have to type in folderName.dev like wordpress.dev.

    My quick reading of the code snippets showed some incorrect single quote character usage, this can be very tricky as different editors apply different interpretations and your PHP engine only wants to see the single quote character which on my keyboard is beside the semicolon key.

    Also suggest that you get going with a standard theme which will give you confidence that you can compare your files to the ones which work. You may have already done this.

    • This reply was modified 6 years, 4 months ago by RossMitchell.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Cannot link CSS file’ is closed to new replies.