Skip Navigation

[Résolu] 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 Il y a 9 années et 3 mois. 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)

Ce sujet contient 8 réponses, a 2 voix.

Dernière mise à jour par loher Il y a 9 années et 2 mois.

Assisté par: Waqas.

Auteur
Publications
#295405
CustomPostType.jpg

Hello.

I created a custom post type and the permalink is now as lien caché

I want these permalinks to be as lien caché

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

Les langues: Anglais (English )

Fuseau horaire: 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 lien caché, 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 lien caché

And I want lien caché

¿How I can do it?

#296627

Waqas
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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. lien caché) 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

Les langues: Anglais (English )

Fuseau horaire: 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

Les langues: Anglais (English )

Fuseau horaire: 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:

- lien caché
- http://stackoverflow.com/questions/16664579/url-rewriting-via-wordpress-rewrite-or-htaccess-solved

#298241

OK, thanks...

Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.

Ce ticket est maintenant fermé. Si vous êtes un client de Toolset et que vous avez besoin d'aide, veuillez ouvrir un nouveau ticket d'assistance