them

Anatomy of an HTML5 WordPress theme

This site has been written in HTML5 and used to use WordPress to manage the content. I’ll explain why I used HTML5, describe the structure of the theme templates, and show some of the ways I tried to tame WordPress’s tendency to add mess to the source code.

As this is my personal site I wanted to experiment with using HTML5, CSS3, and WAI-ARIA. All these documents are currently working drafts and subject to change. However, the web documents and applications of the future are going to be written in HTML5 and I wanted to see the benefits of using it to markup static documents. Using CSS 2.1, let alone the CSS3 selectors and properties that some browser vendors have implemented, has many advantages for controlling the presentation of semantically coded documents. For this reason I am not going to avoid using basic CSS 2.1 selectors just to faithfully reproducing this site’s design in IE6. However, I have tried to accommodate IE 7 and IE 8 users by using an HTML5 enabling script so that the new HTML5 elements can be styled in those browsers if users have Javascript enabled.

HTML5 templates

I started with a static prototype of this site developed on my local server. WordPress makes it very easy to create your own templates and, therefore, it is no problem to use HTML5. This theme only has 3 main templates: index, single, and archive. There are of course templates for 404s, attachments, comments, etc., but I won’t discuss them as they are all based on the 3 main templates. All the templates include ARIA roles as an accessibility aide.

The single.php template has this rough structure:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="default.css">
</head>

<body>
  <header role="banner"></header>
  <nav role="navigation"></nav>
  <article role="main">
    <header>
      <time datetime="YYYY-MM-DD"></time>
      <h1></h1>
    </header>
    <footer></footer>
  </article>
  <nav></nav>
  <aside role="complementary"></aside>
  <footer role="contentinfo">
    <small></small>
  </footer>
</body>
</html>

The first line of the document is the HTML5 DOCTYPE. The new <article> element contains the content of each post. The same structure is used for the index.php template except that there are several articles displayed on each page and the ARIA role value of main is not used. In contrast, the archive.php template houses all the article excerpts in a <section> element with the ARIA role of main because the list of archived posts is itself the main content of the document.

A clean theme

WordPress tends to add classes, elements, and other bits of code in certain places. I haven’t used any of the WordPress functions that add class names to the body and to elements wrapping a post and also wanted to avoid cluttering the source code with any other unnecessary markup. This required a bit of fiddling around with the theme’s functions.php file. I’m not a PHP developer so this might not be pretty!

Removing actions from wp_head()

WordPress has a hook called wp_head that sits in the header.php of most themes. To avoid it inserting unwanted code into the <head> of the document I used the remove_action function to disable the functions that were responsible. The following code was added to the functions.php file of my theme:

// Remove links to the extra feeds (e.g. category feeds)
remove_action( 'wp_head', 'feed_links_extra', 3 );
// Remove links to the general feeds (e.g. posts and comments)
remove_action( 'wp_head', 'feed_links', 2 );
// Remove link to the RSD service endpoint, EditURI link
remove_action( 'wp_head', 'rsd_link' );
// Remove link to the Windows Live Writer manifest file
remove_action( 'wp_head', 'wlwmanifest_link' );
// Remove index link
remove_action( 'wp_head', 'index_rel_link' );
// Remove prev link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
// Remove start link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
// Display relational links for adjacent posts
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
// Remove XHTML generator showing WP version
remove_action( 'wp_head', 'wp_generator' );

Source: WPEngineer.com: Cleanup WordPress Header

Removing an empty <span>

If you want to create excerpts you can either write them into the excerpt box or use the <--more--> quicktag in the WordPress editor. I just wanted the first paragraph of my posts to be used as the excerpt and so using the in-editor tag was the most practical approach I was aware of. However, when you do this WordPress will insert an empty <span> in the post’s content. This element has an id so that the area following the excerpt can be targeted by “more” or “continue reading” links. I removed both the empty <span> and the jump link by adding the following code to the functions.php file of the theme:

// removes empty span
function remove_empty_read_more_span($content) {
  return eregi_replace("(<p><span id="more-[0-9]{1,}"></span></p>)", "", $content);
}
add_filter('the_content', 'remove_empty_read_more_span');

Source: Ganda Manurung: Remove Empty Span Tag On WordPress

// removes url hash to avoid the jump link
function remove_more_jump_link($link) {
  $offset = strpos($link, '#more-');
  if ($offset) {
    $end = strpos($link, '"',$offset);
  }
  if ($end) {
    $link = substr_replace($link, '', $offset, $end-$offset);
  }
  return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');

Source: WordPress Codex: Customizing the Read More

Displaying images in the excerpt

For posts that display nothing but a photograph (yes, they will be shit but I’m hoping it gets me using my camera a bit more often) I wanted the image to show up in the archives. Equally, if the first paragraph of a post contained a link I wanted that to be preserved. The default the_excerpt() template tag doesn’t allow for this so it needed some modifying. I added a new function, which is just a modified version of the core excerpt function, to the functions.php file and then made sure that the template tag executed this function rather than the one contained in the core WordPress files.

function improved_trim_excerpt($text) {
   if ( '' == $text ) {
      $text = get_the_content('');
      $text = strip_shortcodes( $text );
      $text = apply_filters('the_content', $text);
      $text = str_replace(']]>', ']]&amp;gt;', $text);
      $text = strip_tags($text, '<p><img><a>');
      $excerpt_length = apply_filters('excerpt_length', 55);
      $words = explode(' ', $text, $excerpt_length + 1);
      if (count($words) > $excerpt_length) {
         array_pop($words);
         array_push($words, '[...]');
         $text = implode(' ', $words);
         $text = force_balance_tags($text);
      }
   }
   return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');

Source: Aaron Russell: Improving WordPress’ the_excerpt() template tag

I prefer not to have empty elements in the markup and so I needed a way to conditionally insert the “Older entries”, “Newer Entries”, etc., links into templates. The solution I’m using here, which isn’t perfect, is to add this to functions.php:

function show_posts_nav() {
  global $wp_query;
  return ($wp_query->max_num_pages > 1);
}

Source: Eric Martin: Conditional navigation links in WordPress

And then to wrap the navigation markup in the templates with the following:

<?php if (show_posts_nav()) : ?>
<nav>
   <ul>
      <li><?php next_posts_link('&#171; Older Entries') ?></li>
      <li><?php previous_posts_link('Newer Entries &#187;') ?></li>
   </ul>
</nav>
<?php endif; ?>

Summary

It’s fairly easy to create a simple site with HTML5 and to use WordPress to deliver it. At the moment there are issues with Internet Explorer because you cannot style HTML5 elements unless you use Javascript. However, HTML5 redefines the meaning of certain elements (such as <dl>, which has become a more versatile “description list”) and allows block elements to be wrapped in a link. Therefore, there is still benefit in using the HTML5 DOCTYPE even if you do not make use of the new elements.

Further reading

  1. HTML5 working draft
  2. HTML5 differences from HTML4
  3. Accessible Rich Internet Applications (WAI-ARIA) 1.0




them

Us vs. them [electronic resource] : redefining the multi-generational workplace to inspire your employees to love your company, drive innovation, and embrace change / Jeff Havens

Havens, Jeff, author




them

Why American elections are flawed (and how to fix them) [electronic resource] / Pippa Norris

Norris, Pippa, author




them

Sikh group lauds USCIRF for recognising violation against them



  • DO NOT USE Indians Abroad
  • World

them

The tech headaches of working from home and how to remedy them

From shoddy Wi-Fi to digital distractions, our tech can make remote work miserable. Brian X Chen has tips on how to overcome the problems





them

Transforming mathematics problems in Indonesian primary schools by embedding Islamic and Indonesian contexts / Neni Mariana

Mariana, Neni, author




them

Sangaku reflections : a Japanese mathematician teaches / J. Marshall Unger

Unger, J. Marshall, author




them

The Official ACT Mathematics Guide


 

Are you prepared to do your best on the ACT mathematics section test?

The Official ACT Mathematics Guide is the only test prep resource created by the makers of the ACT to prepare you for the mathematics ACT test. This step-by-step guide reviews the entire ACT mathematics test, allowing you to familiarize yourself with the types of questions you can expect to see on test day. You'll learn the math you need to know, as well as how to approach each question



Read More...




them

Climate change is destroying our coral reefs. Here's how scientists plan to save them

Ecologists are studying resilient reefs to unlock their secrets and preserve others for generations to come




them

Unusual monooxygenase mechanism adds oxygen to molecules without oxidizing them

Aminoperoxide adduct on the enzyme's cofactor leads to these nonoxidative oxygenation reactions




them

Glowing plants light themselves up

Researchers teach plants the glow-in-the-dark trick used by tropical mushrooms




them

Big win for Deloitte, BSR in IL&FS case where government was seeking to ban them

The Bombay High Court said that the Ministry of Corporate Affairs (MCA) can’t take action against the two.




them

A mathematical introduction to electronic structure theory: iterative solution of symmetric quasi-definite linear systems / Lin Lin (University of California, Berkeley, California), Jianfeng Lu (Duke University, Durham, North Carolina)

Online Resource




them

The physical and mathematical foundations of the theory of relativity: a critical analysis / Antonio Romano, Mario Mango Furnari

Online Resource




them

Einstein equations: physical and mathematical aspects of general relativity: Domoschool 2018 / Sergio Cacciatori, Batu Güneysu, Stefano Pigola, editors

Online Resource




them

Atomicity through fractal measure theory: mathematical and physical fundamentals with applications / Alina Gavriluţ, Ioan Mercheş, Maricel Agop

Online Resource




them

Mathematics of quantum computing: an introduction / Wolfgang Scherer

Online Resource




them

Using Mathematica for quantum mechanics: a Students Manual / Roman Schmied

Online Resource




them

Gravitational-wave astronomy: exploring the dark side of the Universe / Nils Andersson, Mathematical Sciences and STAG Research Centre, University of Southampton, Southampton, UK

Dewey Library - QC179.A53 2020




them

An introductory path to quantum theory: using mathematics to understand the ideas of physics / Stephen Bruce Sontz

Online Resource




them

Mathematica Nutrition RSS Feed




them

City limits: why Australia's cities are broken and how we can fix them / Jane-Frances Kelly and Paul Donegan

Online Resource




them

NBFCs ask FM to offer credit guarantees to banks on loans extended by them

Industry has also pitched for SPV with initial funding from govt, to help refinance small and mid-sized NBFCs




them

Mathematical modelling in education research and practice: cultural, social and cognitive influences / Gloria Ann Stillman, Werner Blum, Maria Salett Biembengut, editors

Online Resource




them

Summus Mathematicus et Omnis Humanitatis Pater: the Vitae of Vittorino da Feltre and the Spirit of Humanism / by Anja-Silvia Goeing

Online Resource




them

Can your pets get coronavirus, and can you catch it from them?

It was previously reported that lions and tigers in New York’s Bronx Zoo had become infected with SARS-CoV-2, and they were displaying symptoms of COVID-19. Now, it seems that there is evidence that other species, namely cats and dogs, can become infected with the virus, though they respond differently to it than humans do. This week's blog post below discusses the possibility of catching COVID-19 from a dog or a cat.




them

Calculations for molecular biology and biotechnology : a guide to mathematics in the laboratory / Frank H. Stephenson

Stephenson, Frank Harold




them

A primer of mathematical writing : being a disquisition on having your ideas recorded, typeset, published, read, and appreciated / Steven G. Krantz

Krantz, Steven G. (Steven George), 1951- author




them

Blossoms : and the genes that make them / Maxine F. Singer

Singer, Maxine, author




them

Mathematica Early Childhood RSS Feed




them

Mathematica Disability RSS Feed





them

Lactobacillus fermentum CECT5716 prevents renal damage in NZBWF1 mice model of systemic lupus erythematosus

Food Funct., 2020, Accepted Manuscript
DOI: 10.1039/D0FO00578A, Paper
Néstor de la Visitación, Iñaki Robles-Vera, Marta Toral, Francisco O’Valle, Javier Moleon, Manuel Gómez-Guzmán, Miguel Romero, Marcos Duarte, Manuel Sanchez, Rosario Jimenez, Juan Duarte
The aim of this work was to evaluate whether the immune-modulatory bacteria Lactobacillus fermentum CECT5716 (LC40) protects kidneys in a female mouse model of lupus with hypertension. Twenty-week-old NZBWF1 (lupus)...
The content of this RSS Feed (c) The Royal Society of Chemistry




them

Ariana Grande and Justin Bieber's quarantine anthem 'Stuck with U' is winning over the internet; watch

Ariana Grande and Justin Bieber's quarantine anthem 'Stuck with U' is winning over the internet; watch




them

&lsquo;Shouted at them to wake up, train was louder&rsquo;

‘Shouted at them to wake up, train was louder’




them

ITC is first to hike cigarette prices post budget; makes them 10-20% dearer

Price increase brought on by spike in National Calamity Contingency Duty announced in Budget




them

Implementing Accountable Care Organizations: Ten Potential Mistakes and How to Learn From Them

Interview with Stephen M. Shortell, PhD, MPH, MBA, author of Implementing Accountable Care Organizations: Ten Potential Mistakes and How to Learn From Them




them

If Accountable Care Organizations Are the Answer, Who Should Create Them?

Interview with Victor R. Fuchs, PhD, author of If Accountable Care Organizations Are the Answer, Who Should Create Them?




them

Professional Boundaries: What to Do When Clinicians Ask Other Clinicians to Prescribe Medications for Them

In this episode of JAMA Professionalism: Best Practice, Edward H. Livingston, MD looks at the case of a physician requesting prescription medication from a colleague to examine professional boundaries between physicians and options for managing those boundaries. Shiphra Ginsburg, MD and Wendy Levinson, MD, authors of the related article, join Dr Livingston to discuss the best options for handling this challenging situation. Arthur S. Hengerer, MD, chair of the Federation of State Medical Boards discusses the legal and licensure ramifications of physicians prescribing for other clinicians and Kate E. Engelhardt, MD, and D. Brock Hewitt, MD, MPH, practicing physicians, relate their experience with other clinicians asking them to prescribe medications.




them

Mathematics and calculations for agronomists and soil scientists / David Clay, C. Gregg Carlson, Sharon Clay, T. Scott Murrell

Clay, David (David E.)




them

ICNPAA 2018 World Congress: 12th International Conference on Mathematical Problems in Engineering, Aerospace and Sciences: conference date, 3-6 July 2018: location, Yerevan, Armenia / editors, Seenith Sivasundaram

Online Resource




them

The epistle of the number, by Ibn al-Ahdab: the transmission of Arabic mathematics to Hebrew circles in medieval Sicily / by Ilana Wartenberg

Rotch Library - QA23.W37 2015




them

Al-Suyūṭī, a polymath of the Mamlūk period: proceedings of the themed day of the First Conference of the School of Mamlūk Studies (Ca' Foscari University, Venice, June 23, 2014) / edited by Antonella Ghersetti

Rotch Library - PJ7760.S89 Z59 2014




them

Angels in America : a gay fantasia on national themes / Tony Kushner

Kushner, Tony, author




them

The greatest jigsaw puzzle of them all




them

The marriage record of Reynolds, M. L. and Barthem, Ella




them

To Bring Them Within Reach




them

Cesar and Casimiro with an unidentified dignitary between them




them

Waterfront. Tall slender palm trees, water behind them, buildings in background including Soreno Hotel