Home › Types Community Support › [Resolved] How to hide type of post in permalink
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | - |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
Tagged: Setting up custom fields, Types plugin
Related documentation:
Hello.
I created a custom post type and the permalink is now as hidden link
I want these permalinks to be as hidden link
I have probed all the options in the config of the custom type and I don't have any solution.
How can I try to get it?
Thanks for your answer.
Can you please provide some debug information about your site? Please see https://toolset.com/faq/provide-debug-information-faster-support/ for more information.
I have enabled debug information area for your next reply.
My site is hidden link, but the site is not yet visible.
This site is a portal for companies and I have created the custom post type "companies".
Now, the permalink of this posts are hidden link
And I want hidden link
¿How I can do it?
Please consider these steps.
1) Add this code to your theme's functions.php file:
add_filter('post_type_link', 'remove_post_type_slug', 1, 2); function remove_post_type_slug($url, $post) { if (!is_object($post) || 'companies' != get_post_type($post)) { return $url; } if (strpos('%cpt_slug%', $url) < 0) { return $url; } return str_replace('%cpt_slug%/', '', $url); }
Please make sure if the CPT slug is 'companies', if it is different, replace 'companies' with appropriate slug in above code.
2) Go to edit your CPT, and add %cpt_slug% under Options -> 'Use a custom URL format' (see attached). And save your CPT.
The second step will prepend $cpt_slug% in place of companies (i.e. hidden link) and the first step will filter the permalink (in case a companies CPT post is visited), for %cpt_slug% and will strip it off the permalink.
Please let me know if this solution works for you or not.
Hello.
It does not work properly.
The permalink displays fine, but when accessing the company page the result is a 404.
I have attached a image with 4 screens, with the whole process.
Please consider a little change in add_filter() in below code:
add_filter('post_type_link', 'remove_post_type_slug', 10, 2); function remove_post_type_slug($url, $post) { if (!is_object($post) || 'companies' != get_post_type($post)) { return $url; } if (strpos('%cpt_slug%', $url) < 0) { return $url; } return str_replace('%cpt_slug%/', '', $url); }
And remember to update your permalink settings under Dashboard -> Settings -> Permalinks. You don't need to change anything here, just click the 'Save Changes' button and it should flush and updated the rewrite table.
Then try again, if it works or not. Please let me know thanks.
I'm Sorry, It does not work, continue with 404 🙁
Can you please give a try to a 3rd party plugin for managing the redirections (i.e. 301 Redirects and etc)? Since your requirements are around custom URL handling, other than the scope of Types, a 3rd party plugin may help.
You may also try custom URL Rewriting in .htaccess. Following articles may be of some help:
- hidden link
- http://stackoverflow.com/questions/16664579/url-rewriting-via-wordpress-rewrite-or-htaccess-solved
OK, thanks...
The forum ‘Types Community Support’ is closed to new topics and replies.