简体   繁体   English

如何从wordpress的当前页面URL替换http://?

[英]How to Replace the http:// from the current page url of wordpress?

Hi I tried to Replace the http:// or https:// from the current url of wordpress site. 您好我试图从wordpress网站的当前网址替换http:// or https:// I tried to replace the http:// by str_replace . 我试图http:// by str_replace替换http:// by str_replace I fetch the current url by the_permalink(); 我通过the_permalink();获取当前网址the_permalink();

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

that above code is not working but when i trying to get the url from admin input similar to this 上面的代码不起作用,但当我试图从管理输入获取类似于此的URL

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

That Get Option is working Perfect but for the permalink is not working why any suggestion would be great. 获取选项是完美的,但由于永久链接不起作用,为什么任何建议都会很好。

Thanks, vicky 谢谢,薇薇

Finally I Get the suggestion tried by googling here is the one that i tried. 最后我得到谷歌搜索尝试的建议是我试过的那个。

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

I use the get_permalink(); 我使用get_permalink(); instead of the_permalink and it works perfect thanks. 而不是the_permalink,它完美的感谢。 I Tried to close this question. 我试图关闭这个问题。 But this information that i tried is helpful for someone. 但是我试过的这些信息对某人有帮助。

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

Thanks, vicky 谢谢,薇薇

<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>

This will return you the current page URL.. 这将返回当前页面的URL ..

Your syntax isn't right. 你的语法不对。

If you want links to be http:// on an https:// site use <a href="<?php echo str_replace('https://','http://',get_permalink());?>"> ; 如果您想在https://网站上使用http://链接,请使用<a href="<?php echo str_replace('https://','http://',get_permalink());?>"> ;

Otherwise use <a href="<?php echo str_replace('http://','https://',get_permalink());?>"> 否则使用<a href="<?php echo str_replace('http://','https://',get_permalink());?>">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM