admin管理员组文章数量:1332359
I've seen a few "remove last" slash, but not how to remove both the first and last slash.
I've tried:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
ltrim($post_url_rel, '/');
rtrim($post_url_rel, '/');
But it still says /postname/
Anybody has any idea why this didn't work?
I've seen a few "remove last" slash, but not how to remove both the first and last slash.
I've tried:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
ltrim($post_url_rel, '/');
rtrim($post_url_rel, '/');
But it still says /postname/
Anybody has any idea why this didn't work?
Share Improve this question asked Jun 26, 2020 at 7:54 JoBeJoBe 1712 silver badges11 bronze badges1 Answer
Reset to default 2It's because you're not actually putting the result of ltrim()
and rtrim()
back into the variable. Those functions return the trimmed value, they don't modify the passed variable. So you need to do this:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
$post_url_rel = ltrim($post_url_rel, '/');
$post_url_rel = rtrim($post_url_rel, '/');
Or better yet, just use trim()
, which will remove it from both ends:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
$post_url_rel = trim($post_url_rel, '/');
本文标签: customizationRemove slashes (both before and after) in relative post url
版权声明:本文标题:customization - Remove slashes (both before and after) in relative post url 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742317111a2452039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论