如何在商店页面上添加div?

时间:2016-04-27 15:57:53

标签: javascript php wordpress woocommerce

我正在使用Wordpress& Woocommerce,我想在我的商店页面上添加一个div,就在ul产品列表的正上方。我知道这个命令在functions.php文件中起作用:

function woa_content_before_shop() {
    echo "<h1>Hello</h1>" ;
}
add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');

但是当我用div标签替换h1标签时,它会崩溃。谁能告诉我我做错了什么和/或如何纠正这个问题?提前谢谢!

2 个答案:

答案 0 :(得分:2)

  

如果我将echo "<h1>Hello</h1>" ;替换为echo "<div class"title">Hello</div>" ;页面无法加载 - T.Doe 15秒前

那是因为你没有逃避那里的内部双引号。

所以:(你在=之后忘记了一个class标志)

echo "<div class=\"title\">Hello</div>" ;

它会起作用。

echo '<div class="title">Hello</div>' ;
单引号中的

答案 1 :(得分:0)

最好的是你使用“模板覆盖”方法:

将主题文件夹中的woocommerce / templates /文件夹复制到yourtheme / woocommerce /

在该文件夹中,您可以根据心脏内容修改html结构,并使用它来代替woocommerce标准html模板。

完成后,打开这两个文件:

/wp-content/themes/your-theme/woocommerce/shop/wrapper-start.php /wp-content/themes/your-theme/woocommerce/shop/wrapper-end.php 并修改html以匹配你的。