Custom post type permalink shows blog/ in the single page - wordpress

I have created a custom post type and it permalink shows blog/ into the single page,
For eg : www.example.com/blog/event/wine-tasting/
I need this blog/ to be removed from the single page URL and it should come like,
www.example.com/event/wine-tasting/

I did some research and came up with this post:
When you register the custom post type, you have to specify that the
rewrite rule shouldn't be prepended with the existing URL structure.
In short, this means that this line in your register_post_type call:
'rewrite' => array('slug' => 'projects'), should turn into this:
'rewrite' => array('slug' => 'projects','with_front' => false), For
more info, check out the rewrite argument from the codex entry on
register_post_type
edit: just make sure that, after updating the code, you flush the
rewrite rules by visiting Settings > Permalinks. Otherwise you'll
still see the old links. - andreiio
Also found these 3 resources that may help you if you get stumped from another question found here - by Sophia:
WordPress.org Topic
TutsPlus
Another Question

Related

Custom permalinks structure for custom posts

I have a SEO problem as the structure of the site on WordPress is squad.
The site has ordinary cutters and are custom. They are structurally interested in information, but not in the URL. The task of tie them. The solution has never been found on the Internet.
Example:
Page
https://website.com/page1
https://website.com/page2
Custom Post Type
https://website.com/custom/page1/post1
https://website.com/custom/page2/post2
I need cut /custom/ and put this post1 under page1 of that page and another posts under another pages.
In register_post_type I was made rewrite
`
'rewrite' => [
'slug' => '/',
'with_front' => false
],
`
so this remove my /custom/. Can any say me where I can find guide how to transfer this custom_post_type under /page*/?
I tried change permalinks via permalinks plugin, but it doesn't solve my issue.

WordPress archive/taxonomy location

I'm struggling with this, despite being okay at WordPress dev.
I've created a custom post type called links
I've also created a custom taxonomy called link-type
All works fine when using archive.php in the root of the theme.
However I want links to be a child page of resources so:
example.com/links/ would become example.com/resources/links/
And clicking on a taxonomy term link for example downloads would take you to example.com/resources/links/downloads/
I'm aware of has_archive and rewrite and with_front and slug but can't understand how to use these to achieve the aforementioned structure.
As always, expert help is much appreciated.
When you register your post type, just add whatever you want to the slug in the rewrite argument, forward slashes are acceptable in slugs.
$args = array(
'labels' => $labels,
...
'rewrite' => array(
'slug' => 'resources/links',
'with_front' => true
),
);
This will give you https://example.com/resources/links/, even if you have a page already at https://example.com/resources/.
I almost forgot, you'll need to make sure your flush your rewrite rules (this can be done programatically when the CPT is registered, or you can just go to your Settings > Permalinks option page and click Save Changes to accomplish the same thing one time.

Wordpress "custom post type permalinks" plugin generates 404 Page not found

I need the links of all personalized posts and taxonomies to be structured with the name of the category (s) they belong to.
Unfortunately the theme used for my site generates a new type of post and the new taxonomy programmatically and performs the rewrite of their permalink.
To solve this problem I configured the "Custom Post Type Permalinks" plugin which works, but only halfway:
- the permalinks of taxonomies are generated correctly and are accessible from the site.
- the permalinks of the posts are generated correctly, but are not accessible from the site and return a page with a "404 Page not found" error.
In my httpd.conf the line LoadModule rewrite_module modules/mod_rewrite.so is not commented.
What can I do?
let me give you a deeper idea about what we’d like to get. We would really appreciate if you could help us reaching it, by letting us know where to operate.
We would like all the tours’ url to be made up like this: www.sitename.com/$category_father/$category_child/$name_of_my_post Moreover, we would like all the tours’ taxonomies url to be made up like this: www.sitename.com/$category_father/$category_child
At the moment your Tourmaster plugin creates the taxonomies and the tours as below:
www.sitename.com/tour/$name_of_my_post
www.sitename.com/tour-category/$category_child
In order to avoid editing the plugin code and prevent any updates conflicts we installed the plugin “Custom Post Type Permalinks”. It partially solves the taxonomies problem and partially the tours one, generating almost correct urls which are unfortunately not reachable.
www.sitename.com/tour/$category-father/$category_child/$name_of_my_post
www.sitename.com/tour/tour-category/ $category_father/$category_child
Referring to the readme.txt file within www.sitename.com/wp-content/plugins/custom-post-type-permalinks/ we could notice the following example code.
register_post_type( 'foo',
array(
"public" => true,
'has_archive' => true,
"rewrite" => ["with_front" => true],
"cptp_permalink_structure" => "%post_id%"
) );
So we edited the Tourmaster plugin code replacing the rewrite array within the file www.sitename.com/wp-content/plugins/tourmaster/include/tour-option.php with the array [“with_front” => true], but we did not get any result. When you saw the url working, it was due to a temporary reset of the CPTP settings.

Change Permalink of content type

I have a wordpress that has several different content types. I have a spanish version of the site, and in some cases I need to change the permalink structure to match the language.
For example, one content type is a product. Currently the permalink structure is as follows:
http://www.example.com/product/product-name/
however I would need to make it:
http://www.example.com/productos/product-name/
I tried to set it in the initial "register_post_type" method under "rewrite". It didn't seem to do anything.
How can I make this change?
Thanks,
Dan
Try specifically setting the "slug" value under "rewrite":
'rewrite' => array( 'slug' => 'productos' )
If it still doesn't work, make sure to flush your WP cache if you have one activated.

Mixing Wordpress 3.7.1 Page Templates and Custom Post Types

Overview
I have a Custom Post Type called Locations. When the user visits /locations, I would like them to see some general information about all the locations. When the user visits /location/{a-location}, I would like them to see specific information about "a-location". Sounds easy enough.
1st Solution Attempt
I created a Locations page in the Wordpress dashboard to hold the content for the /locations url. I then created an archive-locations.php file and a single-location.php. archive-locations.php pulls info out of the Locations page and it lists all of the custom post type Locations. When the user clicks on a link for a location, the user gets redirected to /locations/{a-location} and single-location.php gets called. This almost does the trick, but it just doesn't feel right and it's creating some other problems.
The Problem
When a user visits /locations I would prefer to be working with a page template for the Locations page (instead of the archive-locations.php page). I'm using the Yoast plugin to specify a custom meta title and description for each page. Since archive-locations.php is being used, all of this meta gets ignored.
2nd Solution Attempt
So I created a page-locations.php template for the Locations page and I was hoping that it would get called instead of the archive-locations.php. Unfortunately, it does not. I then tried removing the archive-locations.php thinking that maybe it was taking precedence. That didn't help either; Wordpress simply renders index.php. If I disable the Custom Post type and visit /locations, then my page template is called correctly. It looks like naming a custom post type the same name as a page causes Wordpress some issues. However, I need to be somewhat similar for the URL structures to work out. /locations needs to pull from a page template; /locations/{a-location} needs to pull from another php pfile.
Question
Is there any way to get page templates and custom post types with similar slugs to work together? If not, I guess my only option is to enhance my header.php and be smarter about determining the title and description when I'm on /locations.
Here's the code that registers my custom post type in case I'm doing something wrong:
$args = array(
'labels' => $labels,
'description' => 'Holds our location specific data',
'public' => true,
'menu_position' => 20,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes' ),
'hierarchical' => true,
'has_archive' => true,
'rewrite' => array('with_front' => false, 'slug' => 'locations') //remove /news/ from the permalink when displaying a custom post type
);
register_post_type( 'locations', $args );
(I also tried changing has_archive to false, but it didn't help.)
What you are trying to do, I once managed to get done easily. I mean having custom post type and use its slug with cusotm page.
Did you try to flush rewrite rules? (just visit Permalink page and save the rules as they are)
So I created a page-locations.php template for the Locations page and I was hoping that it would get called instead of the archive-locations.php. Unfortunately, it does not. I then tried removing the archive-locations.php thinking that maybe it was taking precedence. That didn't help either; Wordpress simply renders index.php
You do not write, how do you load your page template. Do you rely on automatic WP connection of pageslug and page-pageslug.php or you set page template through Page attributes menu?

Resources