0

I am building a full design into WordPress for the first time and I am trying to load in stylesheets and script files but all I seem to be getting is the text output of the location.

What I have is below..

wp_enqueue_style('reset', bloginfo('template_url') . '/reset.css');
wp_enqueue_style('style', bloginfo('stylesheet_url'), array('reset'));
wp_enqueue_style('rhino', bloginfo('template_url') . '/rhinoslider-1.05.css', array('reset','style'));

Do I need to put this inside the link tags or something? I thought it would do it all itself; as what's the point loading it that way if it doesn't do it itself? I know it makes sure the same file isn't included twice or something, but if you have to include the link tags yourself and then WP decides not to include the file then you are left with blank link tags!?

Lastly, should I set these up beforehand so I can just call them via their handles? If so, where? functions.php?

Edit: I also tried putting the below in my themes functions.php file but got the same results.

add_action( 'after_setup_theme', 'mmw_new_theme_setup' );

function mmw_new_theme_setup() {

    /* Add theme support for post formats. */   
    add_theme_support( 'post-formats' );

    /* Add theme support for post thumbnails. */    
    add_theme_support( 'post-thumbnails' );

    /* Add theme support for automatic feed links. */   
    add_theme_support( 'automatic-feed-links' );

    /* Add theme support for menus. */  
    add_theme_support( 'menus' );

    /* Load style files on the 'wp_enqueue_scripts' action hook. */
    add_action( 'wp_enqueue_scripts', 'mmw_new_load_styles' );

}

function mmw_new_load_styles() {

    $foo = bloginfo('template_url') . '/reset.css';
    $bar = bloginfo('template_url') . '/rhinoslider-1.05.css';

    wp_enqueue_style('reset', $foo);
    wp_enqueue_style('style', bloginfo('stylesheet_url'), array('reset'));
    wp_enqueue_style('rhino', $bar, array('reset','style'));

}
4

2 回答 2

1

When storing values in a variable via PHP use:

get_bloginfo()

So your new function would now look like:

function mmw_new_load_styles() {

    $foo = get_bloginfo('template_url') . '/reset.css';
    $bar = get_bloginfo('template_url') . '/rhinoslider-1.05.css';

    wp_enqueue_style('reset', $foo);
    wp_enqueue_style('style', bloginfo('stylesheet_url'), array('reset'));
    wp_enqueue_style('rhino', $bar, array('reset','style'));

}

And be more semantic! It makes code for beginners easier to look at. ($foo could be $resetCssUrl)

于 2012-08-20T21:55:52.197 回答
0

I was having similar issues.

The register / enqueue scripts are so that you can globally assign your functions to load in the correct order. You can call them from the page that your working in but it is considered better practice do it this way.

My template has a functions.php but its nealry empty! It sepreates the scripts into 7 subchapters, theme-options, theme-functions, themes-js, etc. Here is my themes.js.php file but this could quite easily placed in your file inside your wp-content/themes/functions.php My themes-js.php file

于 2012-08-18T13:15:42.143 回答