Version Description
- Initial release.
=
Download this release
Release Info
Developer | valeriosza |
Plugin | Remove Category URL |
Version | 0.1.0 |
Comparing to | |
See all releases |
Version 0.1.0
- index.php +4 -0
- readme.txt +72 -0
- remove-category-url.php +115 -0
index.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Nothing to see here
|
3 |
+
header("HTTP/1.1 403 Forbidden");
|
4 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Remove Category URL ===
|
2 |
+
Contributors: valeriosza
|
3 |
+
Tags: categories, category base, category, permalinks, URL structure, links, seo, cms, wpml, URL
|
4 |
+
Requires at least: 3.1
|
5 |
+
Tested up to: 4.1
|
6 |
+
Stable tag: 0.1.0
|
7 |
+
License: GPLv2
|
8 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=P5QTGDB64SU8E&lc=US&item_name=WordPress%20Plugins&no_note=0&cn=Adicionar%20instru%c3%a7%c3%b5es%20especiais%20para%20o%20vendedor%3a&no_shipping=1¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
9 |
+
|
10 |
+
This plugin removes '/category' from your category permalinks. (e.g. `/category/my-category/` to `/my-category/`)
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
This plugin will completely remove the '/category/' from your permalinks ( e.g. `mydomain.com/category/my-category/` to `mydomain.com/my-category/` ).
|
15 |
+
|
16 |
+
No configuration is required
|
17 |
+
|
18 |
+
= Features =
|
19 |
+
|
20 |
+
1. Better and logical permalinks like `mydomain.com/my-category/` and `mydomain.com/my-category/my-post/`.
|
21 |
+
2. Simple plugin - No configuration is required.
|
22 |
+
3. No need to modify wordpress files.
|
23 |
+
4. Doesn't require other plugins to work.
|
24 |
+
5. Compatible with sitemap plugins.
|
25 |
+
6. Compatible with WPML.
|
26 |
+
7. Works with multiple sub-categories.
|
27 |
+
8. Works with WordPress Multisite.
|
28 |
+
9. Redirects old category permalinks to the new ones (301 redirect, good for SEO).
|
29 |
+
|
30 |
+
= Heads up: =
|
31 |
+
|
32 |
+
Read the [FAQ](https://wordpress.org/plugins/remove-category-url/faq/) before use.
|
33 |
+
|
34 |
+
Want to help? Use the [support](https://wordpress.org/support/plugin/remove-category-url)
|
35 |
+
|
36 |
+
== Installation ==
|
37 |
+
|
38 |
+
1. Upload `remove-category-url.zip` to the `/wp-content/plugins/` directory
|
39 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
40 |
+
3. That's it! You sould now be able to access your categories via http://mydomain.com/my-category/
|
41 |
+
|
42 |
+
== Frequently Asked Questions ==
|
43 |
+
|
44 |
+
= Why should I use this plugin? =
|
45 |
+
|
46 |
+
Use this plugin if you want to get rid of WordPress' "Category base" completely. The normal behaviour of WordPress is to add '/category' to your category permalinks if you leave "/category" blank in the Permalink settings. So your category links look like `mydomain.com/category/my-category/`. With this plugin your category links will look like `mydomain.com/my-category/` (or `mydomain.com/my-category/sub-category/` in case of sub categories).
|
47 |
+
|
48 |
+
= Will it break any other plugins? =
|
49 |
+
|
50 |
+
As far as I can tell, no. I have been using this on several blogs for a while and it doesn't break anything.
|
51 |
+
|
52 |
+
= Won't this conflict with pages? =
|
53 |
+
|
54 |
+
Simply don't have a page and category with the same slug. Even if they do have the same slug it won't break anything, just the category will get priority (Say if a category and page are both 'xyz' then `mydomain.com/xyz/` will give you the category). This can have an useful side-effect. Suppose you have a category 'news', you can add a page 'news' which will show up in the page navigation but will show the 'news' category.
|
55 |
+
|
56 |
+
= The plugin has been uninstalled, but the slug /category/ did not reappear why? =
|
57 |
+
|
58 |
+
A particular installation does not allow the rewrite feature in disabling the plugin. Try after disabling the plugin, save permanent links again.
|
59 |
+
|
60 |
+
== Screenshots ==
|
61 |
+
|
62 |
+
1. No Category URL
|
63 |
+
|
64 |
+
== Changelog ==
|
65 |
+
|
66 |
+
= 0.1.0 =
|
67 |
+
* Initial release.
|
68 |
+
|
69 |
+
== Upgrade Notice ==
|
70 |
+
|
71 |
+
= 0.1.0 =
|
72 |
+
* Initial release.
|
remove-category-url.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Remove Category URL
|
4 |
+
Plugin URI: https://github.com/valeriosouza/remove-category-url
|
5 |
+
Description: This plugin removes '/category' from your category permalinks. (e.g. `/category/my-category/` to `/my-category/`)
|
6 |
+
Version: 0.1.0
|
7 |
+
Author: Valerio Souza
|
8 |
+
Author URI: http://valeriosouza.com.br/
|
9 |
+
*/
|
10 |
+
|
11 |
+
/* hooks */
|
12 |
+
register_activation_hook(__FILE__, 'remove_category_url_refresh_rules');
|
13 |
+
register_deactivation_hook(__FILE__, 'remove_category_url_deactivate');
|
14 |
+
|
15 |
+
/* actions */
|
16 |
+
add_action('created_category', 'remove_category_url_refresh_rules');
|
17 |
+
add_action('delete_category', 'remove_category_url_refresh_rules');
|
18 |
+
add_action('edited_category', 'remove_category_url_refresh_rules');
|
19 |
+
add_action('init', 'remove_category_url_permastruct');
|
20 |
+
|
21 |
+
/* filters */
|
22 |
+
add_filter('category_rewrite_rules', 'remove_category_url_rewrite_rules');
|
23 |
+
add_filter('query_vars', 'remove_category_url_query_vars'); // Adds 'category_redirect' query variable
|
24 |
+
add_filter('request', 'remove_category_url_request'); // Redirects if 'category_redirect' is set
|
25 |
+
|
26 |
+
function remove_category_url_refresh_rules()
|
27 |
+
{
|
28 |
+
global $wp_rewrite;
|
29 |
+
$wp_rewrite->flush_rules();
|
30 |
+
}
|
31 |
+
|
32 |
+
function remove_category_url_deactivate()
|
33 |
+
{
|
34 |
+
remove_filter('category_rewrite_rules', 'remove_category_url_rewrite_rules'); // We don't want to insert our custom rules again
|
35 |
+
remove_category_url_refresh_rules();
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Removes category base.
|
40 |
+
*
|
41 |
+
* @return void
|
42 |
+
*/
|
43 |
+
function remove_category_url_permastruct()
|
44 |
+
{
|
45 |
+
global $wp_rewrite;
|
46 |
+
global $wp_version;
|
47 |
+
if ($wp_version >= 3.4) {
|
48 |
+
$wp_rewrite->extra_permastructs['category']['struct'] = '%category%';
|
49 |
+
} else {
|
50 |
+
$wp_rewrite->extra_permastructs['category'][0] = '%category%';
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Adds our custom category rewrite rules.
|
56 |
+
*
|
57 |
+
* @param array $category_rewrite Category rewrite rules.
|
58 |
+
*
|
59 |
+
* @return array
|
60 |
+
*/
|
61 |
+
function remove_category_url_rewrite_rules($category_rewrite)
|
62 |
+
{
|
63 |
+
$category_rewrite=array();
|
64 |
+
/* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */
|
65 |
+
if (class_exists('Sitepress')) {
|
66 |
+
global $sitepress;
|
67 |
+
remove_filter('terms_clauses', array($sitepress, 'terms_clauses'));
|
68 |
+
$categories = get_categories(array('hide_empty' => false));
|
69 |
+
add_filter('terms_clauses', array($sitepress, 'terms_clauses'));
|
70 |
+
} else {
|
71 |
+
$categories = get_categories(array('hide_empty' => false));
|
72 |
+
}
|
73 |
+
|
74 |
+
foreach($categories as $category) {
|
75 |
+
$category_nicename = $category->slug;
|
76 |
+
if ( $category->parent == $category->cat_ID ) {
|
77 |
+
$category->parent = 0;
|
78 |
+
} elseif ($category->parent != 0 ) {
|
79 |
+
$category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
|
80 |
+
}
|
81 |
+
$category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
|
82 |
+
$category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
|
83 |
+
$category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]';
|
84 |
+
}
|
85 |
+
// Redirect support from Old Category Base
|
86 |
+
global $wp_rewrite;
|
87 |
+
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
|
88 |
+
$old_category_base = trim($old_category_base, '/');
|
89 |
+
$category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]';
|
90 |
+
return $category_rewrite;
|
91 |
+
}
|
92 |
+
|
93 |
+
function remove_category_url_query_vars($public_query_vars)
|
94 |
+
{
|
95 |
+
$public_query_vars[] = 'category_redirect';
|
96 |
+
return $public_query_vars;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Handles category redirects.
|
101 |
+
*
|
102 |
+
* @param $query_vars Current query vars.
|
103 |
+
*
|
104 |
+
* @return array $query_vars, or void if category_redirect is present.
|
105 |
+
*/
|
106 |
+
function remove_category_url_request($query_vars)
|
107 |
+
{
|
108 |
+
if(isset($query_vars['category_redirect'])) {
|
109 |
+
$catlink = trailingslashit(get_option( 'home' )) . user_trailingslashit( $query_vars['category_redirect'], 'category' );
|
110 |
+
status_header(301);
|
111 |
+
header("Location: $catlink");
|
112 |
+
exit();
|
113 |
+
}
|
114 |
+
return $query_vars;
|
115 |
+
}
|