WordPress+WooCommerce希伯来语产品链接复制转URL编码问题求解
解决WordPress/WooCommerce希伯来语产品链接复制编码问题的方法
以下是几个可行的解决思路:
修改固定链接输出逻辑
可以通过WordPress钩子强制输出未编码的希伯来语slug,添加以下代码到主题的functions.php文件或自定义代码插件(如Code Snippets)中:add_filter('post_type_link', 'fix_hebrew_product_link', 10, 2); function fix_hebrew_product_link($link, $post) { if ($post->post_type === 'product') { $decoded_slug = rawurldecode($post->post_name); $link = str_replace($post->post_name, $decoded_slug, $link); } return $link; }这段代码会针对产品类型的链接,将编码后的slug替换为原始希伯来语文本,让页面输出的链接href属性直接使用未编码的UTF-8内容。
针对性处理WooCommerce产品链接
如果只想针对WooCommerce产品做调整,可使用专属钩子:add_filter('woocommerce_get_permalink', 'fix_woocommerce_hebrew_permalink', 10, 2); function fix_woocommerce_hebrew_permalink($permalink, $product) { $decoded_slug = rawurldecode($product->get_slug()); return str_replace($product->get_slug(), $decoded_slug, $permalink); }调整复制方式与浏览器设置
部分浏览器默认会对非ASCII字符的URL进行编码复制,可尝试右键点击链接选择「复制链接地址」,而非直接选中链接文本复制;现代浏览器默认已开启UTF-8编码支持,无需额外调整。注意事项
- 修改代码前请备份相关文件,使用自定义代码插件可避免主题更新导致代码丢失;
- 代码生效后需清除WordPress缓存及浏览器缓存,确保新链接逻辑正常加载。
内容的提问来源于stack exchange,提问作者davidasor
相关产品推荐
相关产品推荐

