Tag Info

New answers tagged

3

Thank you for the response everyone. I played around with macemmek's solution and I think it led me to an even better solution: add_filter( 'wp_unique_post_slug_is_bad_attachment_slug', '__return_true' ); That is all that is needed. This will automatically 'skip' the default assigned slug on any attachment. So an attachment that might normally get the ...


3

You may hook wp_unique_post_slug() and append some string to the original slug if the post is an attachment type. The original slug based on post title will remain free. UPDATED after Rachel Baker's comment: original slug suffix is some random string. It does not guarantee uniqueness but may be enough for simple use cases. add_filter( ...


1

Tom's comment is correct, in that this is normal behaviour and there is not much you can do to stop it. But you can change slugs after things are uploaded/created. While you shouldn't do this if the links are known/publicised/listed on search engines, if you're just trying to fix this problem occasionally after an upload then you can edit the slug of the ...


0

As user9279 suggested (albeit a bit hard to understand), go to your Settings -> Permalinks and save them again. This tends to fix issues like this (as well as, for example, a 404 when viewing a newly created custom post type). If this doesn't work, I suggest you look at the order of the registration for the taxonomy / post. The taxonomy should exist before ...


0

Just further on @Matthew Boynes answer, if you're interested in getting the parent slug (if any) also then I've found this function useful: function mytheme_get_slugs() { if ( $link = get_permalink() ) { $link = str_replace( home_url( '/' ), '', $link ); if ( ( $len = strlen( $link ) ) > 0 && $link[$len - 1] == '/' ) { ...


2

This can also be caused by uploading images with the same file name as the post/page. In my case, I uploaded an image called 'careers.jpg' before I created a page called 'Careers', so the page was getting the '-2' appended. To fix it, I just changed the slug on the image, then I was able to change the slug on the page.


1

Try this if you want to link your CPT archive in a menu: 'has_archive' => true, 'rewrite' => array( 'slug' => 'generic', 'with_front' => false ), After you re-save your permalinks, you can then add the link to your menu like this example: www.example.com/generic



Top 50 recent answers are included