简体   繁体   English

我如何使用冒号 ':' .. 获取我的 wordpress 网站 url?

[英]how do i get my wordpress website url with Colon ':' ..?

add_action( 'init', function() {

    add_shortcode( 'site_url', function( $atts = null, $content = null ) {
        return site_url();
    });

});

I'm Using The Short Code [ site_url ] and My Short Code Function Returned https//shad-pro.com/contact-us我正在使用短代码[ site_url ]和我的短代码功能返回https//shad-pro.com/contact-us

How Do I get The Proper Url With Colon :我如何使用冒号获得正确的Url :

Image Link图片链接

First: Why do you create an add_action to init to make a shortcode?第一:你为什么要创建一个 add_action 到 init 来制作一个短代码?

Second, the function site_url () is deprecated by Wordpress for its native function home_url ().其次,函数 site_url() 被 Wordpress 弃用,因为它的原生函数 home_url()。

Try to correct the code as follows:尝试更正代码如下:

function create_site_url()
{
    return home_url();
}

add_shortcode('site_url', 'create_site_url');

home_url() reference: https://codex.wordpress.org/Function_Reference/home_url home_url() 参考: https ://codex.wordpress.org/Function_Reference/home_url

add_shortcode() reference: https://codex.wordpress.org/Function_Reference/add_shortcode add_shortcode() 参考: https ://codex.wordpress.org/Function_Reference/add_shortcode

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

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