Support » Plugin: Theme Check » A bug which identifies tags incorrectly in the stylesheet

  • Resolved Jesin A


    Running this plugin on the theme I developed I got the following error

    WARNING: Found wrong tag, remove before { from your style.css header.

    But I did not have the Tags: field in styles.css at all so why didn’t I get

    RECOMMENDED: Tags: is either empty or missing in style.css header.

    Finally I found that the following block of CSS code was causing the problem.

    .post-tags:before {
    /*Some styles here*/

    After a bit of digging into the plugin’s code I found the culprit on line 235 of checkbase.php

    if ( preg_match('|Tags:(.*)|i', $theme_data, $tags) )
    $tags = array_map( 'trim', explode( ',', wp_kses( trim( $tags[1] ), array() ) ) );
    $tags = array();

    The first line matches the first string containing “Tags:” case insensitively which was why .post-tags: matched and before { detected as something NOT present in $allowed_tags list.

    Fixing it:

    Change |Tags:(.*)|i to |^Tags:(.*)|i so that only strings that start with “tags” are matched.

    Match the string “Tags:” only if it is inside comments /* */


    Reproducing the error:

    Remove “Tags:” from the header of “style.css” and have something in your CSS code like

    .something-tags:pseudo {

    Hope Simon Prosser and Samuel Wood will fix it in the next release.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    This is a bit of an edge case thing. You could simply add some valid tags to the top of the stylesheet and it would be eliminated.

    Note that theme-check is specifically meant for themes that are intended to be submitted to the repository, as a sort of “pre-flight” check system. Every theme submitted to the repository probably will have valid Tags in the header of the stylesheet.

    Also, requiring the Tags bit to be at the front of the line would not work, because many themes have spaces in their comments on the left side, for various stylistic reasons. It needs to catch those too. Your second suggestion might work, but only shoves the problem to cases where somebody has tags: in a comment later.

    Hi Samuel you’re right about the problem with the first regex but the second one seems foolproof to me.

    I checked it with the regex testing tool with the following options

    Enter regular expression here:

    Enter your data here:

    Theme Name: Twenty Thirteen
    Theme URI:
    Author: the WordPress team
    Author URI:
    Description: The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.
    Version: 1.0
    License: GNU General Public License v2 or later
    * {
    	-webkit-box-sizing: border-box;
    	-moz-box-sizing:    border-box;
    	box-sizing:         border-box;
    summary {
    	display: block;
    video {
    	display: inline-block;
    audio:not([controls]) {
    	display: none;
    	height: 0;
    [hidden] {
    	display: none;
    html {
    	font-size: 100%;
    	overflow-y: scroll;
    	-webkit-text-size-adjust: 100%;
    	-ms-text-size-adjust: 100%;
    License URI:
    Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
    Text Domain: twentythirteen
    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.

    Type: Perl
    Function: preg_match
    Flags: None

    As you said I separated the “Tags:” from the header comments block and put it below and looking at the [1] index of the Resultset: I see only the tag values.

    The reason I’m stressing on this is because it misleads new developers. If someone forgets to put “Tags:” in the header comments and has a class or id selector with the string “tags” followed by a pseudo class they would get a WARNING telling them about a “wrong tag” instead of missing “Tags:”

    When I got this error I thought that either somewhere the syntax of my CSS is wrong or this plugin has a problem with the :before pseudo class.

    If all this seems too much to do please include more details in the WARNING message for non-allowed tags like

    WARNING: Found wrong tag, remove %s from the Tags: field in your style.css header.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A bug which identifies tags incorrectly in the stylesheet’ is closed to new replies.