Doctype前的随机空白

时间:2013-07-13 作者:Adaz

我正在研究一个非常简单的主题,它只是一个单页网站。

明天早上我要去度假,昨晚我被要求把这个网站上线。嗯,在我打开IE之前,一切都很顺利(在我开发主题之前,我已经在IE中测试了html)-出于某种原因,IE触发了怪癖模式,一切看起来都一团糟。我在IE中查看了源代码,显然在doctype之前有一些额外的空间。

然后我在chrome开发工具中查看了该站点,看起来我的标题内容放在了body元素中?

enter image description here

我以前也有过类似的问题,但我通过删除?> 在我的功能中。php和所有包含文件。这在这里似乎不起作用。

代码如下:

标题。php

<!DOCTYPE html>
<!--[if lt IE 6]>     <html class="no-js ie lt-ie9 lt-ie8 lt-ie7 lt-ie6" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 6]>        <html class="no-js ie ie6 lt-ie9 lt-ie8 lt-ie7" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 7]>        <html class="no-js ie ie7 lt-ie9 lt-ie8" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 8]>        <html class="no-js ie ie8 lt-ie9" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 9]>        <html class="no-js ie ie9" <?php language_attributes(); ?>> <![endif]-->
<!--[if IEMobile]>    <html class="no-js iemobile" <?php language_attributes(); ?>> <![endif]--> 
<!--[if gt IE 9]><!--><html class="no-js" <?php language_attributes(); ?>> <!--<![endif]-->

    <head>
    <meta charset="<?php bloginfo( \'charset\' ); ?>" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width" />
    <!--[if IE 6]>
    <script src="/js/third-party/pngfix.js"></script>
    <script>
        DD_belatedPNG.fix(\'.logo a\');
    </script>
    <![endif]-->
    <script src="<?php bloginfo(\'template_directory\'); ?>/js/third-party/modernizr.min.js"></script>
    <link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,700,800" rel="stylesheet">
    <link href="<?php bloginfo(\'template_directory\'); ?>/style.css" rel="stylesheet" />
    <?php wp_head(); ?>
</head>
<body>
    <header class="site-header">
        <div class="wrapper">
            <h1 class="logo">
                <a href="<?php bloginfo(\'url\'); ?>"><?php bloginfo(\'name\'); ?></a>
            </h1>
            <nav class="main-nav">
                <ul class="special-nav">
                    <!--<li class="distinct free-trial-launcher"><a href="#">Free Trial</a></li>-->
                    <li><a href="//admin.brandview.com/login/retailview">Login</a></li>
                </ul>
            </nav>
        </div>
    </header>
    <section class="site-feature">
        <div class="wrapper"></div>
    </section>
索引。php/页。php(基本相同,只是page.php中没有标题或日期)

<?php get_header(); ?>
    <section class="site-content wrapper">
        <?php if ( have_posts() ) :
                  while ( have_posts() ) :
                      the_post(); ?>

        <?php the_content(); ?>

        <?php endwhile;
              else: ?>

        <p>Sorry, no posts matched your criteria.</p>

        <?php endif; ?>
    </section>
<?php get_footer(); ?>
页脚。php

    <footer class="site-footer">
        <div class="footer-nav wrapper">
            <nav class="contact-details">
                <h3>Contact Details</h3>
                <p class="footer-nav-label">Telephone:</p>
                <ul>
                    <li>
                        <a href="tel:0844 357 9970">0844 357 9970</a>
                    </li>
                </ul>
                <p class="footer-nav-label">Email:</p>
                <ul>
                    <li>
                        <a href="mailto:[email protected]">[email protected]</a>
                    </li>
                </ul>
            </nav>
            <nav>
                <h3 class="invisible">Learn More</h3>
                <ul>
                    <li>
                        <a href="http://www.retaildatallc.com">Learn more about Retail Data</a>
                    </li>
                    <li>
                        <a href="http://www.brandview.com">Learn more about Brand View</a>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="copyrights">
            <p class="wrapper">Retail View &reg; is a registered trademark. &copy; Retail View 2013.</p>
        </div>
    </footer>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script>window.jQuery || document.write("<script src=\\"<?php bloginfo(\'template_directory\'); ?>/js/third-party/jquery.min.js\\"><\\/script>")</script>
    <script src="//code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script>
    <script src="<?php bloginfo(\'template_directory\'); ?>/js/main.js"></script>
    <?php wp_footer(); ?>
    <script> 
        RV.init();

        RV.Elements = RV.Elements || {};

        RV.Elements.tplpath = "<?php echo get_template_directory_uri(); ?>";
    </script>
</body>
</html>
功能。php

<?php
    require_once(\'lib/shortcodes.php\');
    require_once(\'lib/filters.php\');

    // ==================================================
    // Register Menus
    // ==================================================
    register_nav_menus( 
        array( 
            \'primary\'               => \'Primary Navigation\'
        )
    ); 

    // Add post thumbnails (feature image)
    add_theme_support( \'post-thumbnails\' ); ?>
过滤器。php

<?php
    // ==================================================
    // Hide Admin Bar
    // ==================================================
    add_filter( \'show_admin_bar\', \'__return_false\' );

    // ==================================================
    // Body Class Modification
    // ==================================================

    function custom_classes($classes) {
        global $wp_query;

        // if there is no parent ID and it"s not a single post page, category page, or 404 page, give it
        // a class of "parent-page"
        if( $wp_query->post->post_parent < 1  && !is_single() && !is_archive() && !is_404() ) {
            $classes[] = "parent-page";
        };

        // if the page/post has a parent, it"s a child, give it a class of its parent name
        if($wp_query->post->post_parent > 0 ) {
            $parent_title = get_the_title($wp_query->post->post_parent);
            $parent_title = preg_replace("#\\s#","-", $parent_title);
            $parent_title = strtolower($parent_title);
            $classes[] = "parent-pagename-".$parent_title;
        };

        // add a class = to the name of post or page
        $classes[] = $wp_query->queried_object->post_name;

        return array_unique($classes);
    };

    add_filter( \'body_class\', \'custom_classes\' );


    // ==================================================
    // Search blog posts only
    // stackoverflow.com/questions/4198842/wordpress-search-function-to-only-search-posts#answer-9885744
    // ==================================================

    function SearchFilter($query) {
        if ($query->is_search) {
            $query->set(\'post_type\', \'post\');
        }
        return $query;
    }

    add_filter(\'pre_get_posts\',\'SearchFilter\');
和短代码。php

<?php
    // ==================================================
    // Clean Shortcode
    // ==================================================

    function parse_shortcode_content( $content ) {

        /* Parse nested shortcodes and add formatting. */
        $content = trim( do_shortcode( shortcode_unautop( $content ) ) );

        /* Remove \'\' from the start of the string. */
        if ( substr( $content, 0, 4 ) == \'\' )
            $content = substr( $content, 4 );

        /* Remove \'\' from the end of the string. */
        if ( substr( $content, -3, 3 ) == \'\' )
            $content = substr( $content, 0, -3 );

        /* Remove any instances of \'\'. */
        $content = str_replace( array( \'<p></p>\' ), \'\', $content );
        $content = str_replace( array( \'<p>  </p>\' ), \'\', $content );

        return $content;
    }

    // move wpautop filter to AFTER shortcode is processed

    remove_filter( \'the_content\', \'wpautop\' );

    add_filter( \'the_content\', \'wpautop\' , 99);

    add_filter( \'the_content\', \'shortcode_unautop\',100 );


    // ==================================================
    // Columns
    // ==================================================

    function create_column($atts, $content = null) {
        extract(shortcode_atts(
            array(
                \'size\'  => \'third\',
                \'class\' => \'\'
            ), $atts
        ));

        $class = $class == \'first\' ? \'first-column\' : \'\';

        $output = \'<div class="column \' . $size . \' \' . $class . \'">\' . $content . \'</div>\';

        return $output;
    }

    add_shortcode("column", "create_column");


    // ==================================================
    // Pop up Window
    // ==================================================

    function popup_window($atts, $content = null) {
        extract(shortcode_atts(
            array(
                \'id\'  => null
            ), $atts
        ));

        $output = \'<div class="pop-up group" data-window-id="\' . $id . \'">
                            \' . do_shortcode($content) . \'
                          </div>\';

        return $output;
    }

    add_shortcode("window", "popup_window");


    // ==================================================
    // Vimeo
    // ==================================================

    function insert_video($atts) {
        extract(shortcode_atts(
            array(
                \'id\'        => \'0\',
                \'align\'     => \'right\',
                \'width\'     => \'400\',
                \'height\'    => \'230\'
            ), $atts
        ));

        $align = $align != \'left\' && $align != \'right\' && $align != \'center\' ? \'right\' : $align;

        $output = \'<iframe src="//player.vimeo.com/video/\' . $id . \'?api=1?player_id=bvvideo&amp;callback=?" width="\' . $width . \'" height="\' . $height . \'" class="video-frame align-\' . $align . \'" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>\';

        return $output;
    }

    add_shortcode("vimeo", "insert_video");
我也可以发送一个。zip主题,如果有帮助的话。

我注意到的一件事是,当您删除函数和标题时,Wordpress会插入一些默认html,并且没有尾随的空格或其他错误,所以我猜这可能与这两个文件有关?

我花了一个晚上的时间试图解决这个问题,但我不能。。。我放弃并张贴在这里的唯一原因是,我需要在度假前(我的航班还有几个小时)将其设置为直播。

编辑#1:

我刚刚查看了资源tham(chrome开发工具)上的原始html:

enter image description here

2 个回复
SO网友:s1lv3r

这对我来说很奇怪:

<!--[if gt IE 9]><!--><html class="no-js" <?php language_attributes(); ?>> <!--<![endif]-->
您正在打开(<!--) 关闭更多注释,html中是否禁止嵌套注释?

SO网友:Adaz

谢谢大家的建议,我很感激。经过长时间的工作,我终于找到了解决办法。。。

当您查看我的编辑#1时,我发布了一个截图,其中doctype前有一个点,因此我开始在google上搜索,我发现:

https://stackoverflow.com/questions/15339108/period-before-doctype

起初我有点怀疑,但当我刷新页面时,我永远不会忘记那种解脱。

结束

相关推荐

在WordPress主题中实现html/css菜单

我有一个HTML/CSS模板,有一个水平菜单。我需要将模板转换为WordPress主题。我一直在看菜单。我在标题中使用了wp\\u nav\\u菜单功能。php文件,并完成了相关功能。php文件。菜单现在以项目符号垂直显示。我现在需要实现菜单,但无法找到正确的css类并将其与menu\\u class参数相关联。请协助。谢谢和问候德巴西斯