我需要更改显示为 http://localhost/product/happy-ninja/ 的链接 至 http://localhost/product/happy-ninja?product= $product_id content-product.php 中的代码如下所示(第 44 行):
<a href="<?php the_permalink($product_id); ?>">
如何添加部分 ?product=
感谢您的帮助
最佳答案
您可以使用 post_link 修改永久链接过滤器
我还没有测试过,但这段代码可能有效:
function append_query_string( $url, $post, $leavename ) {
if ( $post->post_type == 'product' ) {
$url = add_query_arg( 'product', $post->ID, $url );
}
return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );
关于php - 在 content-product.php 上更改 woocommerce 中的产品链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014168/