Hyphen/dash(-) missing in my Custom Post Type URL Slug

Asked
Active3 hr before
Viewed126 times

5 Answers

missingcustom
90%

Must these old pipes be replaced? ,For example URL of the detailed post under this custom post type should be as follows without the custom post type slug., Check this WP plugin and Code: kellenmace.com/remove-custom-post-type-slug-from-permalinks – Manohar tk Feb 17 '20 at 6:23 ,The below function will remove the slug from the permalink

You have to change the

// Registering your Custom Post Type
register_post_type('Earnings Transcripts', $args);

A change like this:

register_post_type('earnings-transcripts', $args);

The below function will remove the slug from the permalink

 function rf_remove_slug($post_link, $post, $leavename) {
    if ('earnings-transcripts' != $post - > post_type || 'publish' != $post - > post_status) {
       return $post_link;
    }
    $post_link = str_replace('/'.$post - > post_type.
       '/', '/', $post_link);
    return $post_link;
 }
 add_filter('post_type_link', 'rf_remove_slug', 10, 3);

The below function will fix the issue of showing the 404 Not found error on the detailed post pages under this custom post type

 function rf_parse_request($query) {
    if (!$query - > is_main_query() || 2 != count($query - > query) || !isset($query - > query['page'])) {
       return;
    }
    if (!empty($query - > query['name'])) {
       $query - > set('post_type', array('post', 'earnings-transcripts', 'page'));
    }
 }
 add_action('pre_get_posts', 'rf_parse_request');
load more v
88%

Support » Plugin: Custom Post Type UI » How to add dash(-) to custom post type slug?,The topic ‘How to add dash(-) to custom post type slug?’ is closed to new replies., Resolved damithruwan1234 (@damithruwan1234) 3 years, 3 months ago Other plugins and custom code allow to use “dash(-)” for slug of custom post type slug. Why this plugin doesn’t allow it? I don’t like underscore. So how can I add “dash(-)” for slug of custom post type. ,Other plugins and custom code allow to use “dash(-)” for slug of custom post type slug.

the template hierarchy/files are based on the slug. So if you had archive-social-media-records.php or single-social-media-records.php those dashes would also need to be updated to archive-social_media_records.php and single-social_media_records.php

archive - social - media - records.php
load more v
72%

Without testing, I'll guess this has nothing to do with the author names specifically, but the fact that author is a built in WordPress query var, and /author/author-name/ is the default permalink for author archives. Change your post type name so the query var no longer clashes, then either change your post type rewrite slug, or change the the default slug for author archives in the init action:,I need to use hyphens in my author slugs (otherwise I'd need to ask my client to manually edit the slug of every single author she creates or created), how to do that?,WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.,I have a CPT called "author". After an hour searching why I get a 404 visiting single pages of this CPT (managed by template "single-author.php") I realize that some do work: those whose slug doesn't include an hyphen !

Without testing, I'll guess this has nothing to do with the author names specifically, but the fact that author is a built in WordPress query var, and /author/author-name/ is the default permalink for author archives. Change your post type name so the query var no longer clashes, then either change your post type rewrite slug, or change the the default slug for author archives in the init action:

global $wp_rewrite;
$wp_rewrite - > author_base = 'blog-author';
65%

//replace dashes (-) with spaces ( )  
$string = "text-with-dashes";
//php string replace
$test = str_replace("-", " ", $string);
75%

To use a built-in template, include the slug of that template within the template attribute. The available templates (and their slugs) are:,Add the template="" attribute with the slug of the template you want to use to display checkout process,The attributes used to setup this pricing table are shown below. Notice how a dash (-) is used in the first and second product’s custom attributes to display a dash in the pricing table.,use the slug of the template as the template attribute’s value if it is located in your theme’s /woocommerce/checkout/ template directory

To use a template located in the default /woocommerce/checkout/my-pricing-table.php:

[woocommerce_one_page_checkout template = "my-pricing-table"]
load more v

Other "missing-custom" queries related to "Hyphen/dash(-) missing in my Custom Post Type URL Slug"