WordPress.org

Ready to get started?Download WordPress

Forums

Smart Archives Reloaded
[resolved] HTML error "document type does not allow element " (5 posts)

  1. swissspaceboy
    Member
    Posted 4 months ago #

    Hello,

    Just installed this plugin and my html validator gives now an error for all pages where SAR is loaded.
    Error message is

    line 940 column 214 - Error: document type does not allow element "link" here

    due to this code that is found at the end of the <body>.

    Any one has a fix for this ?

    <script type='text/javascript' src='http://.../plugins/smart-archives-reloaded/inc/tools.tabs.min.js?ver=1.1.2'></script>
    <script type='text/javascript'>
    jQuery(function ($) { $('head').prepend('<link rel="stylesheet" id="smart-archives-css"  href=".../plugins/smart-archives-reloaded/inc/styles.css?ver=2.0" type="text/css" media="all" />'); });
    </script><script type="text/javascript">
    jQuery( document ).ready( function( $ ) {
    	$( '.tabs' ).tabs( '> .pane' );
    	$( '#smart-archives-fancy .year-list' )
    		.find( 'a' ).click( function( ev ) {
    			$( '.pane .tabs:visible a:last' ).click();
    		} ).end()
    		.find( 'a:last' ).click();
    } );
    </script>

    http://wordpress.org/plugins/smart-archives-reloaded/

  2. scribu
    Member
    Plugin Author

    Posted 4 months ago #

    Your HTML validator is naive; it shouldn't check HTML inside <script> tags.

    You should try the official validator from W3C: http://validator.w3.org/

  3. swissspaceboy
    Member
    Posted 4 months ago #

    Hi Scribu,

    Thanks for answering. I'm using the official W3C validator of course.

    Here is the full output of the page check:

    Error Line 1313, Column 215: document type does not allow element "link" here
    
    …archives-reloaded/inc/styles.css?ver=2.0" type="text/css" media="all" />'); });
    
    The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).
    
    One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

    They propose to escape the html code with //<![CDATA[ //]]>

    like in this example :

    <script type="text/javascript">
    //<![CDATA[
    var output = "<html><body><p>Hi!<\/p><\/body><\/html>";
    //]]>
    </script>

    Do you have some ideas how to change this in files util.php or core.php ?

    Thanks,

    D.

  4. swissspaceboy
    Member
    Posted 4 months ago #

    @all : this is my fix. As I have moved the css of this plugin to my theme stylesheet, there is no need to register the stylesheet.
    So in file core.php, function add_scripts(), comment out this piece of code :

    if ( $add_css ) {
    			$css_dev = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
    
    			wp_register_style(
    				'smart-archives',
    				$plugin_url . "styles$css_dev.css",
    				array(),
    				SAR_VERSION
    			);
    			scbUtil::do_styles( 'smart-archives' );
    		}

    This will avoid having a W3C validator error. Not great as fix but it works.

  5. scribu
    Member
    Plugin Author

    Posted 4 months ago #

    I guess I'll have to eat my words.

    The //<![CDATA[ makse sense, since it's an inline script.

    Here's the change I made: https://github.com/scribu/wp-scb-framework/commit/e1e7cf6d6d6a578c3507bb9f52eb4b70b8fc3f90

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.