用过滤器编辑site_url [英] Edit site_url with filter

查看:146
本文介绍了用过滤器编辑site_url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用WordPress,调用 site_url()会返回完整的网站URL( http://www.example.com
我想要做的是在URL的末尾添加一些东西( add-something-here



我期待的结果是:
http://www.example.com/add-something-here



有人知道如何做到这一点与过滤器?



我试过以下没有成功: p>

 函数custom_site_url($ URL){
返回get_site_url( '/添加出头-这里');
}
add_filter('site_url','custom_site_url');


解决方案

问题在于您正在生成一个循环过滤。功能 get_site_url 正是其中滤波器 SITE_URL 正在被呼叫。



您需要:

$ $ p $ add_filter('site_url','custom_site_url');

功能custom_site_url($网址)
{
如果(is_admin())//你可能不希望在这个管理方
$回报网址;

return $ url。'/ something';

$ / code>

请记住,这可能会产生依赖于真实URL。


With WordPress, calling site_url() returns the full site URL (http://www.example.com) What I'm trying to do is adding something (add-something-here) at the end of the URL with filter.

The result I'm expecting is: http://www.example.com/add-something-here

Does someone know how to do that with filter?

I tried the following with no success:

function custom_site_url($url) {
    return get_site_url('/add-something-here');
}
add_filter('site_url', 'custom_site_url');

解决方案

The problem is that you are producing a loop with this filter. The function get_site_url is exactly where the filter site_url is being called.

You need:

add_filter( 'site_url', 'custom_site_url' );

function custom_site_url( $url )
{
    if( is_admin() ) // you probably don't want this in admin side
        return $url;

    return $url .'/something';
}

Bear in mind, that this may produce errors for scripts that rely on the real URL.

这篇关于用过滤器编辑site_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆