I have several categories in my WordPress blog. All posts are available through domain.tld/post-title. But now I need different urls for certain topics.
Example:
Blog > domain.tld/post-title
Category 1 > domain.tld/category-1/post-title
Category 2 > domain.tld/category-2/post-title
Category 3 > domain.tld/post-title
I would prefer not to use a plugin and set everything via custom-template.php or functions.php. I have seen a few solutions with str_replace, but unfortunately none of them worked properly for me.
I also use different layouts for different categories. So I could also use something inside the template file to change the urls.
This should be available through Wordpress' default functionality by using categories for each post & updating the permalinks.
If you already have the categories in place under "Posts -> Categories"
and have assigned them to each post then your next step would be setting how it is displayed in your Permalinks tab.
Here you can set site-wide URL structure. In your case it would use
/%category%/%postname%/
which would put the category before the title of the post each time the URL is spun up by Wordpress.
Related
I have a website, here is the link for reference and visualization, made with wordpress twentyfourteen theme. Currently, in the main page, the main area have blog posting from all categories (currently news and featured). How can I limit it to list only "news" category ? the reason is I dont want to mix it with featured, so that featured is only listed on the right sidebar.
Here is a screenshot for better understanding:
There is no option to do this, but you can go to Page (or Post) settings and choose if you want to show this page/post manually.
Checkboxes inside page/post settings (check or uncheck):
Featured posts
Newest posts
Also, I recommend to watch tutorial how to hide it in this way:
Source
My website has two blogs. Imagine that their url are mydomain.com/blog1 and mydomain.com/blog2.
I'd like to have post url such as:
mydomain.com/blog1/sample-post-from-blog1
mydomain.com/blog2/sample-post-from-blog2
Posts from both blogs are under 'Post' Wordpress section and I think of differentiating them by tags or categories 'blog1' and 'blog2', although I'm not sure about what's the best practice.
So I'm kind of lost. Anyone has a clue about it?
Yes you can make it by making two separate custom post types for for both of the blogs. do not use default posts for your first blog.
I managed to do this:
I kept blog1 posts within default WP posts
For blog1 posts I defined a custom structure for permalinks: /blog/%postname%/
I created a custom post type for blog2 posts
To avoid the prefix '/blog/' to be applied to blog2 posts, I changed its 'with_front' property to 'false' (ref)
Using qTranslate Slug plugin, I set '/blog2-name/' as a slug for this new custom post type.
I did a great amount of research and came across some solutions like this:
https://wordpress.stackexchange.com/questions/106042/force-wordpress-to-show-pages-instead-of-category
But still it isn't exactly what I'm looking for. First of all let me explain the problem.
I made a page /blog/ and a category 'blog' both make use of the permalink /blog/, disabled the /category/ permalink so the SEO will be correct.
The solutions I came across didn't match the following requirements:
Not using 301 redirects
Disable the /category/ use within Wordpress.
Also make it possible to only replace category when a page id uses the same slug.
I simply like to tell Wordpress to display the page instead of the category.
Why don't you just edit the category template?
Because the page I created uses Visual Composer (Post Masonry Grid) so I can't simple move the design.
Why don't you just use redirects?
I would like to but the permalink of the blog is the same as the page (SEO purpose.)
I know it's a few years later with no solution, but I had the exact same problem you described on one site that was working in other sites. So I did some research on what was different and to help others should they run into the same issue.
Background
example.com is the domain
I have a WP page called "foobar" with content
I have a WP post category called "foobar"
I have a WP post entitled "fun things to do with foobars", and the category is set to "foobar"
Expectations
When I go to example.com/foobar, I want to see the page about foobars, not a WP category page that shows all blog posts with that category.
When I go to the blog post about fun things, the URL is example.com/foobar/fun-things-to-do-with-foobars/
Setup
Here's my setup (it does not require any additional plugins or code edits)
A couple of installed plugins are WP Rocket and Yoast on which I'll focus in this thread.
WP Dashboard->Settings->Permalinks
Select "Custom Structure" and enter /%category%/%postname%/ in the field
On the same page, change "Category base" to a single dot. "." (no quotes, just a single dot/period/full stop
I have Yoast installed, which I had set up to override the permalink settings, but I believe this messed up my task at hand.
WP Dashboard->SEO->Advanced->Permalinks(tab)
"Change URLs->Strip the category base..." = Keep
Then you need to clear the cache. I use WP Rocket for caching, so I flushed the cache and everything now works the way it should.
Edit: make sure you save your changes after steps 3 and 5
I know this topic is old but question is still important.
I will use blog example.
This method is code free, WP native solution. One caveat is that you cannot translate "blog" slug, so this method is only for one language if you don't need to have different words/slugs for other languages.
Create page with slug "blog". Or whatever you like. It must match word you put in next step as base: blog = blog it this example.
Set permalink structure in settings to: /blog/%category/%postname%/ (/ trailing slash on the end is your preference)
Use SEO plugin like Yoast or Seopress Pro (or any other
method) to remove /category from URL.
Go to Settings -> Reading -> "Your homepage displays" section -> "A static page (select below)"
Set your static page for Homepage
Here is the magic: set Posts page to your "Blog" page.
Flush permalinks by visiting and saving settings on Permalink page (without any change).
Then you will get proper URL: /blog/yourcategory/single-post-title/
Breadcrumbs will work, all categories will be hierarchical, and /blog will work as page instead of category.
Most importantly, when you go to your category page you will get /blog/yourcategory URL and it will work as archive page. When you visit single post, then also you get URL /blog/yourcategory/single-post-title/
Breadcrumbs from Yoast should work. I use Seopress Pro and breadcrumbs works like a charm (you have to go to breadcrumbs setting page and select categories for posts and posts for categories and tags if you need them).
If you do it without including /blog in your permalink setting it will still work, you will get page instead of category with proper url for categories, but single post will be /yourcategory/single-post-title.
my website blog is http://hawaiiturtletours.com/category/blog/. This is the only category on the site. I would like to know how can I remove or overwrite the URL for this page only so the new one is http://hawaiiturtletours.com/blog. One of the most suggested solutions in this case to overwrote URLs with the settings /%category%//%postname%/ does not work in my case.
Thanks!
From the WordPress Codex:
The Category base and Tag base are prefixes used in URLs for category
and tag archives, which look like this:
> example.net/wp/category_base/category_name
> example.net/wp/tag_base/tag_name
The default values for these are category and tag. You can change them, but > > you can't remove them from the URLs altogether.
A blog isn't really a category. If you go to WordPress Settings > Reading you'll see the option "Front Page Displays:". Change it to a 'static page' and select a page to be your static front page. You may need to create it at this point. Then you'll want to create a page called "blog" and back in Settings > Reading change "Posts Page:" to be your "blog" page.
This will give you the desired URL hawaiiturtletours.com/blog
I am using this theme: http://www.eleventhemes.com/gridly/
In order for the pages to only show certain posts on certain pages it requires the category folder in front of the slug so if I have a page called graphic-design it has to be accessed this way: domain.com/category/graphic-design. When I go to edit the page in WP it automatically removes the / after the word category.
How can I add a folder name in front of the page name?
That sounds like a bug in the theme. My first guess is that there's a naming collision. I believe "category" is the slug Wordpress uses for displaying post categories, while the theme is trying to use "category" to rewrite page permalinks.
As an experiment, try editing Wordpress' built-in Category base option.
Try going to Dashboard > Settings > Permalinks, and at the bottom under "Category base" set the field to something besides "category", like "mycats" or whatever. For fun try setting it to "category" explicitly and see what happens.