用过滤器编辑site_url [英] Edit site_url with filter
问题描述
使用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
正在被呼叫。
您需要: 请记住,这可能会产生依赖于真实URL。 With WordPress, calling The result I'm expecting is:
Does someone know how to do that with filter? I tried the following with no success:
The problem is that you are producing a loop with this filter. The function You need: Bear in mind, that this may produce errors for scripts that rely on the real URL. 这篇关于用过滤器编辑site_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ $ p $ add_filter('site_url','custom_site_url');
功能custom_site_url($网址)
{
如果(is_admin())//你可能不希望在这个管理方
$回报网址;
return $ url。'/ something';
$ / code> 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.http://www.example.com/add-something-here
function custom_site_url($url) {
return get_site_url('/add-something-here');
}
add_filter('site_url', 'custom_site_url');
get_site_url
is exactly where the filter site_url
is being called.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';
}