Make Wordpress use the page instead of category - php

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.

Related

WordPress url change, only for some categories

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.

Removing / Disabling Wordpress date and /blog links

Solution:
The problem was actually SEO Yoast. It creates "Archives" for posts and authors, creating a whole load of crap on the website.
The current template for our wordpress website originally was html only.
A guy we hired some time ago, did the transfer so to speak, but there are some problems.
At the moment the website contains "www.website.com/blog" and various "www.website.com/2018 or /2018/06" links that google does it's damnedest to index. Some of the links return a 404 occasionally as well.
Because we do daily blog post's everything is naturally copied over to those "/blog" pages. The results is 52% duplicate content (according to Siteliner)
I'm writing here looking for advice, because I don't know how to get rid of them or how to manage them to reduce the SEO related impact. I also didn't find post relating to this specific problem.
(example of the problem "multiorders.com/2018/07/page/2/" )
Our post links are set to website.com/sample-post, someone had suggested adding a "RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ http://yourwebsite.com/$3" into the .htaccess file.
I can tell you the basic structure to avoid the Duplicate content issue and the URL structure issue. Both are really important and can say main factor for Seo purposes.
Structure:
First one, Create a blog page (Already created on your website). On that page there must be shown the all blog posts that you have entered in the admin panel at POSTS menu. The lists of all blogs www.example.com/blog here as you said. In that page there should me pagination that means if you are showing 10 posts per page then the 11th post will be on the www.example.com/blog/2 and so on. (acceptable foe seo purpose).
Secondly, If someone clicks on the post or Read more button it should redirect the
single blog www.example.com/blog-post-name (perfect for seo).
To change the permalink (URL Structure) you have go to the admin settings menu -- permalink menu-- change to post name and Save.
Note: Take a backup before applying
Any questions, please ask..!!
The problem was actually SEO Yoast. It creates "Archives" for posts and authors, creating a whole load of crap on the website. As soon as I disabled those features all the extra pages vanished. Now all I need is to wait for Google to catch up.

Revising WordPress URLs with .htaccess

On my WordPress installation, I have a blog living at http://domain.com/blog. Each individual blog post lives at http://domain.com/post-title.
So that I can more effectively segment page traffic in Google Analytics, I would like to revise my permalink structure so that individual posts live at http://domain.com/blog/post-title.
The challenge, however, is that I also have several pages at http://domain.com/page-title. I do not want to impact those page URLS.
Is there a way that I can modify the permalink structure only of my blog posts? If so, is it then possible to set a rule within .htaccess to redirect from old permalink structure to new?
I believe what you want to accomplish can be easily fixed by visiting the Settings > Permalinks page in wp-admin.
Towards the bottom of the permalink selection radio items, you can choose "Custom Structure", then enter a value like blog/%postname%/
This will have the effect of prepending all of your post slugs with 'blog', while leaving pages' URLs untouched.

Custom Permalink with Page Name Wordpress

I have looked all over the place and can't figure out how to get this to work.
I want my urls for blog posts to look like this: "www.website.com/my-page/category-name/blog-post-title"
The issue I am having is that I have a page called "my-page".
So I have a page "www.website.com/my-page/" which is just a standard wordpress page, but I want the url for the blog post to look like it is under that page.
Here is what I have for the permalink so far:
/my-page/%category%/%postname%/
But this doesn't work and gets a 404 error when opening a blog post.
At this point I don't believe it can be fixed through the wordpress gui, so if anyone has any recommendations, it would be appreciated.
Thanks!
Edit: I wanted to add that the permalink works fine if I remove "/my-page" or if I simply modify it so it does not match the page.
First of all you should not use the category in front of your permalinks as it leads to bad performance (and some posts may have multiple categories): http://ottopress.com/2010/category-in-permalinks-considered-harmful/
The second thing is - it should work. I tried with a fresh installation on WordPress and I get the correct results.
Did you flush rewrite rules / save the new permalink structure?
Did you publish a post?
Is your server correctly configured to use permalinks?
Third possibility - if your permalink structure does not work for some reason you can define a custom permalink structure:
https://codex.wordpress.org/Rewrite_API

Exclude '/category/' from menu links URLs in WordPress

I work with wordpress site, where now category page is accessible from two types of links:
http://SITENAME.com/category/CATEGORY-NAME/
http://SITENAME.com/CATEGORY-NAME/
And from right-side menu the links shown as first type, which is wrong.
I need to setup side-menu links to looks like http://SITENAME.com/CATEGORY-NAME/ (without 'category' in every path).
How it can be done? I haven't found such settings neither in admin panel nor in templates...
I would recommend this plugin:
http://wordpress.org/plugins/wp-no-category-base/
The plugin requires no setup or modifying core wordpress files and will not break any links. It will also take care of redirecting your old category links to the new ones.
If you run a multilanguage site with WPML plugin, try this:
http://wordpress.org/plugins/no-category-base-wpml/

Categories