Newbie : Enqueue stylesheet.
-
I am a PHP programmer, new to wordpress.
I am used to building my own CMS systems and web applications. I thought I’d try wordpress for a variety of reasons. Despite being a PHP expert, I have found trying to learn wordpress to be extremely difficult and frustrating.
Here is one of many examples:
1. I am used to creating applications where I include(‘functions.php’); I tried this in the header.php script and it turns out wordpress automatically includes the functions.php file. WHERE IS THAT DOCUMENTED? From the tutorials, it seems that the only files required for a theme to work are index.php and style.css. Apparently functions.php is automatically included?
So, getting to the point, it seems I have to learn the wordpress conventions – baptism by fire. Fine.
Now I am frustrated because I don’t see how to do even the simplest of things that are supposed to work “simply”.
After many hours of wasted time and trying / failing to load a stylesheet perhaps someone can help.
Here is my index.php file:
<?php get_header(); ?>
<?php the_content(); ?><?php echo get_stylesheet_uri(); ?>
<?php get_footer(); ?>
I can see the stylesheet is properly referenced. That’s who I’m echoing get_stylesheet_uri();
My stylesheet contains the following:
/*
Theme Name: Test Theme
Theme URI: https://themeshaper.com/
Author: ThemeShaper
Author URI: https://themeshaper.com/
Description: The Shape theme is a simple, minimalist theme based on Underscores and the original Shape Theme by Ian Stewart. It was created especially as a learning theme for The ThemeShaper WordPress Theme Tutorial: 2nd Edition.
Version: 2.0
License: GNU General Public License
License URI: license.txt
Tags: light, white, one-column, two-columns, left-sidebar, right-sidebar, flexible-width, custom-backgroud, custom-header, custom-menu, featured-images, flexible-header, microformats, post-formats, rtl-language-support, threaded-comments, translation-ready
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/body {
background-color:#999;
}header {
font-size:24px;
}Should be simple enough.
Here is the header.php file :
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Theme</title>
</head>
<body>
<header><p>I am the header</p></header>suffice to say the html markup is correct for the site.
In the head, if i include:
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>">
I am able to get the stylesheet to work.If I remove the above stylesheet reference, because I’m told the correct way to include a stylesheet is to enqueue it, and try the “correct way”, I cannot get the stylesheet to work.
Here’s my code in the functions.php file:
function mycssScript() {
// Load our main stylesheet.
wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'mycssScript' );The above is the latest attempt. I have tried numerous sites and turorials and examples and nothing is working.
Am I doing something wrong? –Please help ??
- The topic ‘Newbie : Enqueue stylesheet.’ is closed to new replies.