It’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, "https://wordpress.stackexchange.com/");
$post_url_rel = rtrim($post_url_rel, "https://wordpress.stackexchange.com/");
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, "https://wordpress.stackexchange.com/");
Related Posts:
- Custom Post Type, post-formats associated to custom post type > 404 archives
- How to bulk Update URLs to new values?
- Template for displaying CPT / Taxonomy URL issues
- Custom URL Structure for posts with subcategories
- Is there a Standard Format for Clean URLs for Archives of Custom Posts?
- Choose options via url
- Default post type doesn’t display in url
- Is it possible to customize the post according to post format in single.php?
- Customize rel=canonical tag for single blog post
- a little direction on custom post type
- disable Tab post on nav-menus page (Admin)
- Linking to pages/posts within the site
- WP move posts to different path
- Format latest/newest post differently
- Custom taxonomy archive page problem
- Tell WP to use a specific template file in posts
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- relating business and products with custom taxonomy?
- Best Way to Add UnEditable HTML to Posts
- How safe is it to delete old posts edits to save database space?
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- Using setup_postdata() with multi-dimensional array
- Is codex right on deleting post?
- Check if a custom post type has already been created
- WordPress Query Posts From Category Post on Static Page
- Edit multiple custom post types while saving a new or edited post
- Make insterted image point to post url instead of attachment page
- Create a custom posts page
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- if in category but only with post meta
- How to get different Related Posts
- How to add convenient buttons for new custom post statuses
- How to allow multiple thumbnail upload for Posts?
- add external project to web site wordpress on production
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- Show custom post with custom categories with specific slug
- register_post_type permalink
- Display the 2nd category name of a custom post type without error if its null?
- Post is blank when I click on the link
- Auto delete posts based on content text
- How to call posts under a specific category on static front page?
- Querying another post category to match current post and display in loop
- Custom home page with full post for first one only
- How to get the latest URL of my blog?
- Custom Post Limit for homepage only without plugin?
- Display value of custom field at the beginning of a post
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- datepicker value in mysql
- Inserting an example of the last 3 post on to the homepage
- Static pages not working
- Optimize CPT-function with a loop
- Add post tags to previously created custom post type
- Can WordPress handle following functionalities?
- Simple Custom Metabox Not Saving
- Get a term each custom post type
- Change default post style to columns
- Post titles and thumbnails as links to custom post types?
- Inserting Media to WordPress Posts
- How to display only one category in a custom post type?
- Adding a custom post type meta field to rss
- How to restore deleted post related with deleted users
- Help with listing current users submitted custom post type in template file
- Delete post from admin but not from database
- Custom Post Type Single Loop Outputting Wrong Post
- add_rewrite_rule and template redirect not working
- Can Permalink structure of %postname%/%post_id% improve performance
- Getting post and attached image from subdomain
- Custom post type slideshow background images to insert in a plugin
- Organization of time insensitive content
- Custom Select Query – Selecting the Year?
- Deleting old posts
- How To Use Custom Tax of a Post Type
- How to output all taxonomy links from a custom post type in a menu?
- Can I style single post that are in multiple catergories?
- Trying to exclude custom posts based on date, while sorting by custom field
- WordPress Post Deletion Issue
- How Can I Always Display A Particular Post First Using WP_Query?
- What would causes search to return incorrect results?
- Help on conditional statement to accompany wp_insert_post function please?
- Changing permalink of WordPress
- MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
- Hook save_post_cpt not triggered when custom fields are modified
- Change modified date to current date when title updated automatically
- How to prevent to create same url of post, if the previous was deleted?
- Turn off display for custom sidebar post widget when on the post it’s displaying
- Can I show category name in url for only one of my categories?
- WordPress posts have a different URL to the index
- get posts, run a custom query, and join the results
- Posting to WP via URL
- Permalink Short code showing unnecessary link text inside the loop
- search form for custom fields
- How to put the author of the post in the comments?
- Alt text attributes not showing over portfolio images
- Every time I try accessing a post it redirects me to the feed
- How can I make a post sub link?
- Adding an option to post editor to show a site disclaimer or message
- Search results for ACF data
- How to add a custom class attribute into code wrapper? [duplicate]