WordPress Remove category Category logo code implementation version

Source: Internet
Author: User
Keywords WordPress

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

In fact, many of the Internet to remove the classification of the logo, such as a fixed link before adding a small point ".", or to modify the original WordPress program file method, feel the best use is using Plug-ins: No-category-base, the use of plug-ins, not only can category logo removed, And before the visit with Category category directory and do 301 jump, which is very conducive to SEO. Anyway, if you can see this article, then just want to implement this function, and do not want to use plug-ins, citing the nipple big words, I believe that we can see after reading:

In fact, in WordPress, whether you have enabled Plug-ins and themes, as long as you upload them to WordPress, WordPress will be after he put those plug-ins and the topic of the information read out again. So then WordPress each read a plug-in information will be a calendar file (PS: Because the WordPress plugin does not have a fixed information file, as long as the plugin author happy, the plugin directory under any PHP file can be.) So WordPress can only read the information through the calendar file. and the subject information? are in Style.css, that is to say, each theme exists on the theme of the server WordPress will read their style.css, then the number of words in the WordPress speed will slow down, so small v suggested that the theme and plug-ins can not be used and deleted. Plug-ins can be integrated into the theme as much as possible to the theme, because this will reduce the number of WordPress calendar files.

If you read the above article carefully, you can understand why there is this article, haha. Nonsense not to say, our goal is to transplant Plug-ins No-category-base to the theme of the functions.php.

How do I migrate plugins?

Well, that's a problem, if you're just trying to get the results out of the stretch party, okay, Jump to the end of the article to copy the code pasted into your functions.php can be, and then say plug-in transplant to the functions.php in the attention, attention, because I am also WP toss rookie, all the wrong place, look great God pointed out:

In fact, the most important thing is this register_activation_hook, this is the plug-in registration when activated, So directly thrown into the functions.php will certainly be wrong, thrown into the theme, we will modify this here to activate the theme when enabled, then the corresponding for the load-themes.php, good focus is over. Next look directly at the code, I believe you will understand.

Remove classification standard category code version

Note is that when the plugin is disabled to remove the pseudo static rule, here we do not need him, because the theme is not enabled is equivalent to not enable this pseudo static rule, the language is not good, expressed unclear. You know. Copy the following code to the functions.php of your topic to remove the category labels:

Remove Category Flag Code

Add_action (' load-themes.php ', ' no_category_base_refresh_rules ');

Add_action (' created_category ', ' no_category_base_refresh_rules ');

Add_action (' edited_category ', ' no_category_base_refresh_rules ');

Add_action (' delete_category ', ' no_category_base_refresh_rules ');

function No_category_base_refresh_rules () {

Global $WP _rewrite;

$WP _rewrite-> flush_rules ();

}

Register_deactivation_hook (__file__, ' no_category_base_deactivate ');

function No_category_base_deactivate () {

Remove_filter (' category_rewrite_rules ', ' no_category_base_rewrite_rules ');

We don ' t want to inserts our custom rules Recycle

No_category_base_refresh_rules ();

// }

Remove Category Base

http://www.wpmee.com/no_category_base/

Add_action (' init ', ' no_category_base_permastruct ');

function No_category_base_permastruct () {

Global $WP _rewrite, $WP _version;

if (Version_compare ($wp _version, ' 3.4 ', ' < ')) {

For pre-3.4 Support

$WP _rewrite-> extra_permastructs[' category '][0] = '%category% ';

else {

$WP _rewrite-> extra_permastructs[' category ' [' struct '] = '%category% ';

}

}

ADD our custom category rewrite rules

Add_filter (' category_rewrite_rules ', ' no_category_base_rewrite_rules ');

function No_category_base_rewrite_rules ($category _rewrite) {

Var_dump ($category _rewrite); For debugging

$category _rewrite = Array ();

$categories = get_categories (Array (' Hide_empty ' => false));

foreach ($categories as $category) {

$category _nicename = $category-> slug;

if ($category-> parent = = $category-> cat_id)//recursive recursion

$category-> parent = 0;

ElseIf ($category-> parent!= 0)

$category _nicename = get_category_parents ($category-> parent, False, '/', true). $category _nicename;

$category _rewrite[' ('. $category _nicename. ')/(?: feed/)? (Feed|rdf|rss|rss2|atom)/?$ '] = ' index.php?category_name= $matches [1]&feed= $matches [2] ';

$category _rewrite[' ('. $category _nicename. ')/page/? ([0-9]{1,})/?$ '] = ' index.php?category_name= $matches [1]&paged= $matches [2] ';

$category _rewrite[' ('. $category _nicename. '/?$ '] = ' index.php?category_name= $matches [1] ';

}

Redirect support from Category Base

Global $WP _rewrite;

$old _category_base = get_option (' category_base ')? Get_option (' category_base '): ' Category ';

$old _category_base = Trim ($old _category_base, '/');

$category _rewrite[$old _category_base. '/(. *) $ ' = ' index.php?category_redirect= $matches [1] ';

Var_dump ($category _rewrite); For debugging

return $category _rewrite;

}

Add ' category_redirect ' query variable

Add_filter (' Query_vars ', ' no_category_base_query_vars ');

function No_category_base_query_vars ($public _query_vars) {

$public _query_vars[] = ' category_redirect ';

return $public _query_vars;

}

Redirect if ' Category_redirect ' is set

Add_filter (' request ', ' no_category_base_request ');

function No_category_base_request ($query _vars) {

Print_r ($query _vars); For debugging

if (isset ($query _vars[' Category_redirect ')) {

$catlink = Trailingslashit (get_option (' Home ')). User_trailingslashit ($query _vars[' category_redirect '], ' category ');

Status_header (301);

Header ("Location: $catlink");

Exit ();

}

return $query _vars;

}

OK, it's done, look at your classified sign category is not gone? Reprint Please specify: http://www.wpmee.com/no_category_base/Respect Others Labor achievements, thank you for your cooperation!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.