我有一些产品Color 属性我怎么能有这样的东西:
http://example.com/shop/category-name/product-title-color/
在WooCommerce中,我应该如何制作这种永久链接。
我有一些产品Color 属性我怎么能有这样的东西:
http://example.com/shop/category-name/product-title-color/
在WooCommerce中,我应该如何制作这种永久链接。
您可以这样做,将查询附加到永久链接(而不是基本url):
add_filter( \'post_type_link\', \'my_append_query_string\', 10, 4 );
function my_append_query_string( $permalink, $post, $leavename, $sample ) {
if ( $post->post_type == \'shop\' ) {
if (get_option(\'permalink_structure\')){
$permalink = AddStringToUrl($permalink,\'color=red\');
}
}
return $permalink;
}
function AddStringToUrl($current_url, $string) {
return $current_url
. ( stripos($current_url, \'?\') === false ? \'?\' : \'&\' )
. $string;
}
我正在构建一个插件,该插件将用于单个站点,并依赖于add_rewrite_rule 要工作,需要打开永久链接。打开它们并不困难,因为它只是一个站点,但我担心其中一个管理员可能会在不知道自己在做什么的情况下关闭它,并破坏该站点。如何以编程方式强制保持漂亮的永久链接?