Skip Navigation

[Resolved] How to hide type of post in permalink

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

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)

This topic contains 8 replies, has 2 voices.

Last updated by loher 9 years ago.

Assisted by: Waqas.

Author
Posts
#295405
CustomPostType.jpg

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.

#295652

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

#296535

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?

#296627

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

cpt-rewrite-slug.png

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.

#297090
permalink_types.jpg

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.

#297336

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

#297348

I'm Sorry, It does not work, continue with 404 🙁

#297591

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#298241

OK, thanks...

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.