如何在Wordpress中使用功能在店面主题的徽标图像下添加文本

问题描述 投票:-1回答:1

我尝试在徽标图像下面添加一个文本,并在我的孩子主题function.php里面添加以下内容..

add_action( 'storefront_header', 'htdat_below_logo', 21 );
function htdat_below_logo() { ?>
<div style="padding-top:10px;clear: both; text-align: left;color:#ffff">

<span style="margin: 0 0.5em;">Hello</span>
</div>
<?php
}

但没有任何反应。如果我检查页面并手动添加html它正在工作。但是这个功能没有。

在这篇博客中,https://businessbloomer.com/storefront-theme-visual-hook-guide/指的是

@hooked'storefront_site_branding',20

数字20表示初始功能?

谢谢

php css wordpress
1个回答
0
投票

您可以使用动作挂钩:

<header>
   <!-- I want to add html code here -->
   <?php do_action('wpse_myheader'); ?>
</header>

然后你可以使用:

function add_html_to_header { ?>
   <b> Hello World </b>
<?php }
 add_action('wpse_myheader','add_html_to_header');

另一种方法是将静态内容添加到Storefront标头需要挂钩将内容输出到storefront_header的函数您可以通过优先级集控制标记的位置。例如,以下代码段会在网站标题/辅助导航/搜索和主导航之间添加“行”。

add_action( 'storefront_header', 'jk_storefront_header_content', 20 );
function jk_storefront_header_content() { ?>
    <div style="clear: both; text-align: right;">
        Have questions about our products? <em>Give us a call:</em> <strong>0800 123 456</strong>
    </div>
    <?php
}

调整优先级和内联CSS以满足您的要求。


根据WP codex查看当前版本的Storefront的header.php:

/**
 * Functions hooked into storefront_header action
 *
 * @hooked storefront_skip_links                       - 0
 * @hooked storefront_social_icons                     - 10
 * @hooked storefront_site_branding                    - 20
 * @hooked storefront_secondary_navigation             - 30
 * @hooked storefront_product_search                   - 40
 * @hooked storefront_primary_navigation_wrapper       - 42
 * @hooked storefront_primary_navigation               - 50
 * @hooked storefront_header_cart                      - 60
 * @hooked storefront_primary_navigation_wrapper_close - 68
 */
do_action( 'storefront_header' ); ?>

该注释块概述了挂钩到storefront_header操作的所有回调函数(具有优先级)。

如果在店面目录的文件中搜索字符串'storefront_header'的文本,则可以找到这些函数。没有标准的方式来组织这些函数出现的位置,但是您可以从functions.php开始手动跟踪它们,并遵循其中的所有代码。但搜索效率更高。

storefront_site_branding是处理徽标显示方式的函数。它位于storefront/inc/storefront-template-functions.php

© www.soinside.com 2019 - 2024. All rights reserved.