【问题标题】:How to Replace the http:// from the current page url of wordpress?如何从 wordpress 的当前页面 url 替换 http://?
【发布时间】:2013-06-29 10:12:32
【问题描述】:

您好,我尝试从 wordpress 网站的当前网址替换 http:// or https://。我试图替换http:// by str_replace。我通过the_permalink();获取当前网址

<?php echo str_replace(array('http://','https://'),'',the_permalink());?>

上面的代码不起作用,但是当我尝试从类似于此的管理员输入中获取 url 时

<?php echo str_replace(array('http://','https://'),'',get_option('URL'));?>

Get Option 工作完美,但永久链接不起作用,为什么任何建议都会很棒。

谢谢, 维姬

【问题讨论】:

    标签: php wordpress str-replace


    【解决方案1】:

    最后我通过谷歌搜索得到了我尝试过的建议。

     the_permalink() function will print the output before you can perform anything so try uses get_permalink() function instead.
    

    我使用 get_permalink();而不是 the_permalink ,它非常有效,谢谢。我试图结束这个问题。但是我尝试过的这些信息对某人有帮助。

    <?php echo str_replace(array('http://','https://'),'',get_permalink());?>
    

    谢谢, 维姬

    【讨论】:

      【解决方案2】:
      <script type="text/javascript">
                          function current_url(){        
                              return document.URL;
                          }
      
      
       var current_url=window.parent.current_url();   // current_url contains the value of the current URL             
                      </script>
      

      这将为您返回当前页面的 URL..

      【讨论】:

      • 谢谢,我终于找出问题所在。那是我在下面发布的。感谢您花费宝贵的时间。 :)
      • 我得到了完美的当前页面网址。但我的问题是替换当前页面 url 中的 http://。
      • 很高兴您提出通过 javascript 获取当前页面 url 的建议
      • 一旦你有了完整的 URL,你就可以使用它了,因为 php 和 jquery 中有许多用于字符串替换的函数
      【解决方案3】:

      你的语法不对。

      如果您希望 https:// 网站上的链接为 http://,请使用 &lt;a href="&lt;?php echo str_replace('https://','http://',get_permalink());?&gt;"&gt;

      否则使用&lt;a href="&lt;?php echo str_replace('http://','https://',get_permalink());?&gt;"&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-17
        • 1970-01-01
        • 2011-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-18
        相关资源
        最近更新 更多