在特定 div 之后插入一些文本到 WordPress 前端
Insert some text after a specific div into WordPress frontend
我正在自定义 Woocommerce 的前端,所以我想在用户单击“添加到购物车”按钮之前在我的最终价格之后添加文本“/每月”。
我试过了 javascript
jQuery('.woocommerce-variation-price').append(" / month")
但是当我从控制台 运行 它工作时,它在我通过模板中的文件 运行 它时失败。我查看页面代码时仍然可以看到代码,但它没有任何作用。
我在想也许我可以通过 WordPress 挂钩实现这一点。
我已将此插入 functions.php
add_filter( 'the_content', 'permonth_filter' );
function permonth_filter ( $content ) {
if ( is_single() ) {
$content .= '<div class="permonth-filter"> / Per Month </div>' . "
";
} // End IF Statement
return $content;
} // End wpcandy_filterhook_signoff()
在博客末尾添加一些文字 post。
有没有办法在特定 div 和特定 class 之后添加一些文本? woocommerce-variation-price
确保在页面加载后您是 运行 您的 JavaScript。
jQuery( document ).ready(function($) {
// Run your code
$('.woocommerce-variation-price').append(" / month");
}); // end document ready
我正在自定义 Woocommerce 的前端,所以我想在用户单击“添加到购物车”按钮之前在我的最终价格之后添加文本“/每月”。 我试过了 javascript
jQuery('.woocommerce-variation-price').append(" / month")
但是当我从控制台 运行 它工作时,它在我通过模板中的文件 运行 它时失败。我查看页面代码时仍然可以看到代码,但它没有任何作用。
我在想也许我可以通过 WordPress 挂钩实现这一点。
我已将此插入 functions.php
add_filter( 'the_content', 'permonth_filter' );
function permonth_filter ( $content ) {
if ( is_single() ) {
$content .= '<div class="permonth-filter"> / Per Month </div>' . "
";
} // End IF Statement
return $content;
} // End wpcandy_filterhook_signoff()
在博客末尾添加一些文字 post。
有没有办法在特定 div 和特定 class 之后添加一些文本? woocommerce-variation-price
确保在页面加载后您是 运行 您的 JavaScript。
jQuery( document ).ready(function($) {
// Run your code
$('.woocommerce-variation-price').append(" / month");
}); // end document ready