How to achieve a custom post type permalink like this!

How to achieve a custom post type permalink like this!

download

download

Thanks

plugin development – Error 404 change permalink term custom term taxonomy

I’m trying to change the permalink structure of the terms for a custom taxonomy, but it’s returning page 404. I want the URL to be: example.com/products/category/category-name.

I tried to use the term_link filter, I even tried to put a slug different from the custom post type, however, without success. I have also updated wp_options on permanent links

add_action( 'init', 'register_sps_products_post_type' );
function register_sps_products_post_type() {
    register_post_type( 'sps-product',
        array(
            'labels' => array(
                'name' => 'Products',
                'menu_name' => 'Product Manager',
                'singular_name' => 'Product',
                'all_items' => 'All Products'
            ),
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'show_in_nav_menus' => true,
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'post-formats', 'revisions' ),
            'hierarchical' => false,
            'has_archive' => 'products',
            'taxonomies' => array('product-category'),
            'rewrite' => array( 'slug' => 'products' )
        )
    );
    register_taxonomy( 'product-category', array( 'sps-product' ),
        array(
            'labels' => array(
                'name' => 'Product Categories',
                'menu_name' => 'Product Categories',
                'singular_name' => 'Product Category',
                'all_items' => 'All Categories'
            ),
            'public' => true,
            'hierarchical' => true,
            'show_ui' => true,
            'rewrite' => array( 'slug' => '%sps-product%/category', 'with_front' => false ),
        )
    );
}

add_filter('term_link', 'idinheiro_permalink_archive_cpt', 10, 2);
function idinheiro_permalink_archive_cpt( $url ) {
    if ( false !== strpos( $url, '%sps-product%') ) {
        $url = str_replace( '%sps-product%', 'products', $url );
    }
    return $url;
}

woocommerce offtopic – How to add SKU using Permalink Manager PRO

I want to add sku at the end of woocommerce url slug but when i limmit the words to 5 words in slug it did not regenerate the slug and add sku at the end

I use this code in child theme functions.php

function pm_limit_slugs_length($uri) {
    $max_words = 5; // If any part of URI contains more than 5 words, the slug will be limited to first 5 words
    $new_title = '';
    $slugs = explode("https://wordpress.stackexchange.com/", $uri);
    
    for($i=0, $count = count($slugs); $i < $count; $i++) {
        $slug = $slugs($i);
        $words = explode('-', $slug);
        
        $new_title .= "/";
        if(count($words) > $max_words) {
            $new_title .= implode("-", array_slice($words, 0, $max_words));
        } else {
            $new_title .= $slug;
        }
    }
    
    // Remove trailing slashes
    $new_title = trim($new_title, "/");
    
    return $new_title;
}
add_filter('permalink_manager_filter_default_post_uri', 'pm_limit_slugs_length', 99);
add_filter('permalink_manager_filter_default_term_uri', 'pm_limit_slugs_length', 99);

How to 301 redirect WP posts id "/c/94940894" to permalink with post name?

My posts have custom urls

https://demo.com/c/100038431

How can 301 redirect to

https://demo.com/post-name

Thanks ..

Permalink blog page (only) not working

WordPress 5.6, WooCommerce version 4.9.2, PHP Version 7.4.14

Dear,

I am facing a problem with permalinks. When having ‘post name’ selected, permalinks work for all pages expect ‘blog’. In this case, no posts appear on the blog page. Only the page title. When having ‘plain’ permalinks selected, everything works like a charm.

With permalink settings disabled it is working: “https://prnt.sc/xsrlpv”, “https://prnt.sc/xsrmi0”
With permalink settings enabled is not working: “https://prnt.sc/xsrn60”, “https://prnt.sc/xsrns8”

I have troubleshooted by disabling plugins, using other themes, checking the .htaccess file on correct content/permissions, home/blog page correctly set in ‘reading’, but without success. I contacted my hosting company to check if mod_rewrite module is enabled and web directory override rule is set to AllowOverride All (waiting for their reply), but believe the problem is not on server level as other permalinks (e.g about & contact-us pages) work fine.

Thank you very much in advance for your help.

Kind regards,
Quinten

Media Gallery Images – safe to change permalink?

I am new to blogging and learning as I go. I wrote a few posts with lots of images and now that I am learning about SEO, I realize I need to add alt text and have names that are relevant to the image (versus IMG_6473, etc). I already changed my permalinks about a month in and understand how that can create a mess. The last thing I want to do is ruin my site by “redirecting” every image link. Not sure if I should just move on and fix them as I post or go back (I have 1700 images in my media library – all missing alt text, all missing image names that mean anything). Such a mess, but I am prepared to take it on if it is safe for my site and will improve my SEO. I have a travel blog and these posts are some of my best National Parks so I am hoping to eventually have them rank. Thank you for any help.

search – Redirect template based on permalink rather than $wp_query

I’m trying to separate out different templates which utilise WordPress’ search (s query var) along with different post types.

Situation 1: Default WordPress search page (search.php). Example: example.com?s=test

Situation 2: Post type archive (archive-{$post_type}.php), with search and taxonomy query var filtering ability. Example: example.com/questions?s=test&category=wordpress

Situation 2 has a few different final templates based on what post type is being queried.

So far I’ve managed to get the above to work with a function similar to this:

function wpse_redirect_search_page_post_types( $template ) {
    global $wp_query;

    if ( $wp_query->is_search ) {
        if ( get_query_var( 'post_type' ) === 'question' ) {
            return locate_template( 'archive-question.php' );
        }
    }
    return $template;
}
add_filter( 'template_include', 'wpse_redirect_search_page_post_types' );

However I encountered an issue when attempting to filter the search results page with different post types. I’ve got a bunch of checkboxes to filter what post types to show on the search results page, and the moment I’ve got only one post type (eg example.com?s=test&post_type=question) it sets the template to archive-question.php.

In terms of the $wp_query, they’re identical (barring query hash differences) for
example.com?s=test&post_type=question
and
example.com/question?s=test&post_type=question.

What’s the best way to do a check for whether I’m intending to show the search or archive template? The only other way I know how to do this is access the url through $_SERVER('REQUEST_URI'), but I was hoping there was a more WordPress-centric way of checking what template it intends to use.

Final use-case goals:

  • example.com/questions?s=test (archive)
  • example.com/questions (archive)
  • example.com/?s=test (search)
  • example.com/?s=test&post_type=question (search)
  • example.com/?s=test&post_type=question,answer (search)

Remove custo permalink base from CPT custom category and custom tags

I have a ‘resources’ CPT with ‘resources_category’ (custom category) and ‘resources_term’ (custom terms). They are all working, however the category and terms URL’s pick up the base permalink slug (‘news’) which is used for the blog posts.

ie. the following 2 URL’s are working

/resources/

/resources/post-title/

however the taxonomy URL’s are

/news/resources/category/videos/

/news/resources/tags/water/

I wish to change these to (remove the ‘news’)

/resources/category/videos/

/resources/tags/water/

Changing

'rewrite' => array( 'slug' => 'resources/tags', 'with_front' => true ),

to

'rewrite' => array( 'slug' => 'resources/tags', 'with_front' => false ),

returns a 404 error.

seo – Permalink Structure change killed traffic – change back?

As far as I know, it’s normal to lose some of the SEO juice, even when implementing 301 redirects. When you switch to HTTPS (which is a different domain for Google than the original HTTP), you can also expect to lose some ranking in the beginning. However, here, the idea is that, since HTTPS is preferred, the change will eventually improve your rankings compared to before.

So, overall I don’t think it’s a surprise that your ranks and traffic have suffered. The question is whether it will recover in time. I would first try to fix the current situation before switching back as there is no guarantee that that will make things better. Maybe you can check your backlinks and reach out to sites linking to you to switch to the new URLs?

categories – What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?

See: https://wordpress.org/support/article/using-permalinks/

By default, when someone sets their permalink structure to:

/%category%/%postname%/

Post URLs appear like so:

https://example.com/**abc**/some-cool-post/

ABC merely represents the first category of potentially several selected for the post, but unlikely the most appropriate.

I’ve made it so that my writers can select which category should be most prominent, which is saved as post meta for each post, and can be output with the variable $prominent_category.

I would like to automatically replace %category% with $prominent_category in the slug, without the need of registering an additional taxonomy or doing anything else that might be overkill, so that whatever the author sets as their prominent category, say Pizza, that the new structure for the post appears as so:

https://example.com/**pizza**/some-cool-post/

Are either category_rewrite_rules or post_link_category the right choice, or should I be going down a different path?