简体   繁体   English

这个WordPress主题的body标签在哪里?

[英]Where is the body tag in this WordPress theme?

I need to add the ID 'skrollr-body' to the body tag of my website but I can't find the opening body tag anywhere. 我需要在网站的body标签中添加ID“ skrollr-body”,但在任何地方都找不到开头的body标签。 Its a very simple change I know, but the website isn't mine and directory structure is very messy and he's asked me to resolve the issue of the website not scrolling on mobile/tablet (which is due to the body tag not having the ID 'skrollr-body'). 我知道这是一个非常简单的更改,但是网站不是我的,目录结构也很凌乱,他要我解决网站无法在手机/平板电脑上滚动的问题(这是由于body标签没有ID) 'skrollr-body')。

The theme inherits from Genesis, and in the header.php I found this which does mention the body tag, can I add an ID in this snippet of code at all ? 主题继承自Genesis,在header.php中,我发现确实提到了body标签,是否可以在此代码片段中添加ID? - --

genesis_markup( array(
    'html5'   => '<body %s>',
    'xhtml'   => sprintf( '<body class="%s">', implode( ' ', get_body_class() ) ),
    'context' => 'body',
) );

Also, the header.php in the theme it self has nothing to do with the opening body tag: 此外,主题本身中的header.php与开始body标签无关:

<div class="one-third first">
    <a href="">
        <img src="" />
        <img src="" />
    </a>
</div>
<div class="two-thirds">
    <div>
        <p></p>
    </div>
    <div id="callus">
        <a href=""></a>
    </div>
</div>

Any help would be greatly appreciated, if this was a static site instead of a dynamic site with a CMS it would be easiest change possible, but this WordPress directory is so messy and disorganised I can't locate the tag at all. 我们将不胜感激,如果这是一个静态网站,而不是带有CMS的动态网站,将是最容易的更改,但是此WordPress目录是如此混乱且混乱,我根本无法找到该标签。

I almost thought about implementing some jQuery to amend the tag but that seems a bit over the top for such a simple change. 我几乎考虑过实现一些jQuery来修改标签,但是对于这样一个简单的更改,这似乎有点过头了。

Cheers. 干杯。

It looks like the theme you've got is a bit mangled - it's rare to find (or need) a header.php in the child theme of the Genesis Framework. 看来您所拥有的主题有点混乱-在Genesis Framework的子主题中很少(找不到)header.php。

The correct way to add <body> attributes is with the filter that Genesis provides: 添加<body>属性的正确方法是Genesis提供的过滤器:

add_filter( 'genesis_attr_body', 'so3707332_attributes_body' );
/**
 * Add ID attribute to body element.
 *
 * @param array $attributes Existing attributes.
 *
 * @return array Amended attributes.
 */
function so3707332_attributes_body( $attributes ) {
    $attributes['id'] = 'skrollr-body';

    return $attributes;
}

Simply you can find the body tag inside the header.php file of your theme.. replace this: 只需在主题的header.php文件中找到body标记即可。替换此代码:

genesis_markup( array(
    'html5'   => '<body %s>',
    'xhtml'   => sprintf( '<body class="%s">', implode( ' ', get_body_class() ) ),
    'context' => 'body',
) );

with: 与:

genesis_markup( array(
    'html5'   => '<body %s>',
    'xhtml'   => sprintf( '<body class="%s">', implode( ' ', get_body_class('classname') ) ),
    'context' => 'body',
) );

reply if it worked. 回复是否有效。

Best of luck. 祝你好运。

Try with this: 试试这个:

genesis_markup( array(
    'html5'   => '<body %s>',
    'xhtml'   => sprintf( '<body id="skrollr-body" class="%s">', implode( ' ', get_body_class() ) ),
    'context' => 'body',
) );

Or with this: 或与此:

genesis_markup( array(
    'html5'   => '<body id="skrollr-body" %s>',
    'xhtml'   => sprintf( '<body id="skrollr-body" class="%s">', implode( ' ', get_body_class() ) ),
    'context' => 'body',
) );

您应该能够将ID添加到sprintf语句中。

'xhtml'   => sprintf( '<body id="skrollr-body" class="%s">', implode( ' ', get_body_class() ) ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM