在 wordpress 中为 link url 添加前缀

Add prefix to link url in wordpress

我想在 wordpress 站点上添加图像 link,这会将用户重定向到相同 url 但具有不同前缀的另一个页面。例如 页面 url 是我的域。com/post1234 当用户单击此页面上的图像时,它会将用户重定向到 url 我的域。com/md/post1234

以下代码在网站上的每个 post 页面上打印当前页面 url 但我想在 url

中添加 "md" 前缀
<a href="<?php
$Path=$_SERVER['REQUEST_URI'];
$URI='http://www.example.com'.$Path;
?>"><img src="<?php bloginfo('template_url'); ?>/images/sgxx.png">Click Here</a>

请建议执行此操作的正确代码。

试试这个:

<?php
    $domain = get_site_url(); //You can use this or either "http://".$_SERVER[HTTP_HOST];
    $path = $_SERVER[REQUEST_URI];
    $prefix = "/md";
?>
<a href="<?= $domain.$prefix.$path ?>">Link</a>

有关 $_SERVER 的更多信息,请查看下面的 link: http://php.net/manual/en/reserved.variables.server.php