Whenever I add a custom logo to a client’s Moodle theme, I always try to leave the H1 tag and title in the HTML for search engines and screen readers to find. And, since this isn’t the method described in the Moodle Documentation, I thought it was time I shared my method in the name of accessibility and SEO.
Here’s what I’m talking about. What follows was pulled from header.html in the Standard theme folder.
<div id="header-home" class="clearfix">
<h1 class="headermain"><?php echo $heading ?></h1>
<div class="headermenu"><?php echo $menu ?></div>
</div>
All code in this tutorial is presented in green on a black background. Highlighted text will appear in yellow; additions will appear in blue; subtractions will appear in red with a line through the text.
- The first thing you’ll want to do is copy your logo to your theme’s “pix” folder. For example, since I’m using the Standard theme, I would copy my logo to …/moodle/theme/standard/pix/.
- Then, open your theme’s header.html file and search for the following:
- <div id="header-home" class="clearfix">
<h1 class="headermain"><?php echo $heading ?></h1>
<div class="headermenu"><?php echo $menu ?></div>
</div> - <div id="header" class="clearfix">
<h1 class="headermain"><?php echo $heading ?></h1>
<div class="headermenu"><?php echo $menu ?></div>
</div> - Add your logo between h1.headermain and div.headermenu using PHP to designate a relative path to your logo.
- Add a “logo” class to your image for future positioning.
- Save changes and check your theme to make sure you have entered everything correctly. Your header should look something like this, with both your site title AND logo showing:
<h1 class="headermain"><?php echo $heading ?></h1>
<div class="headermenu"><?php echo $menu ?></div>
This should appear twice:
and:
The first appearance (header-home) determines what will appear on your front page only. The second appearance (header) determines what will appear on all other pages. If you want your logo to appear on ALL pages, you will simply have to add it twice, in both places.
<h1 class="headermain"><?php echo $heading ?></h1>
<img src="<?php echo $CFG->themewww .’/’. current_theme() ?>/pix/logo.jpg" />
<div class="headermenu"><?php echo $menu ?></div>
<h1 class="headermain"><?php echo $heading ?></h1>
<img class=”logo” src="<?php echo $CFG->themewww .’/’. current_theme() ?>/pix/logo.jpg" />
<div class="headermenu"><?php echo $menu ?></div>
Now that we have your HTML in order, let’s hide your site title from view without actually “getting rid” of it. We’ll do this using CSS.
- Open your primary CSS document. If you are using the Standard theme, use styles_layout.css. If you are using a NewSchool Learning theme, use styles_base.css, styles_default.css, or styles_themename.css (where themename is the name of the theme you’re using!).
- If you are only adding a logo to the front of your site, add the following to the very bottom of the CSS document opened above.
- And, if you are adding a logo to all pages (and you have made the appropriate additions to header.html noted above), your addition will look like this:
- Save changes and check your site. It should look something like this:
#header-home .headermain {
position:absolute;
left:-9999px;
}
#header-home .logo {
float:left;
}
#header-home .headermain,
#header .headermain {
position:absolute;
left:-9999px;
}
#header-home .logo,
#header .logo {
float:left;
}
If you find that your logo isn’t centering properly, you can always add padding to your image until you get it placed where you like.
header-home .logo {
float:left;
padding:Wpx Xpx Ypx Zpx;
}
In the above example W=”top”, X=”right”, Y=”bottom”, and Z=”left”.





Comments
Wow, got to say, that is a sharp tutorial and your themes look damn good. glad to find someone really doing it right, I’m relatively new to setting up moodle portals. –eric
Very useful and clear tutorial.
Please keep them coming.
Very clear and helpfull explanation.
But what about adding something to the footer?
Is that possible?
Thanks.
yes. You would edit footer.html
My header pic is not appearing. Should i also change the word “current_theme” to the theme i’m using, which is standardgreen?
Thanks for the help and have a great evening!
No. That isn’t necessary; Moodle automatically directs to your current theme. Double check the syntax of the code you have entered. Make sure you have edited the right files. Also, make sure your image is named appropriately in both your CSS and pix folder.
Hai, i have a moodle web site, which was customized by our client. Now we need to change the design of some pages such that they match the requirement specified by the client. For that purpose, can you mention what and where do i need to make the changes ?
Note that the client has used a different style for each page, not of the original moodle.
You can refer to the index page of the site:
http://ks35021.kimsufi.com/moodle
Can you please suggest me where to change the code to get our own index page ?
Leave a Comment