0

In my project, I used a theme named 'ABSOLUTE'. The theme has its own language in registering custom post named "portfolio". The code is not php, so I made the dirty trick by changing the labels of "portfolio" into "cheat/guides/.

//change post labels
function change_post_object_label() {
global $wp_post_types;
    $labels = &$wp_post_types['portfolio']->labels;
    $labels->name = 'Guides/Cheats';
    $labels->singular_name = 'Guide/Cheat';
    $labels->add_new = 'Add Guide/Cheat';
    $labels->add_new_item = 'Add Guide/Cheat';
    $labels->edit_item = 'Edit Guide/Cheat';
    $labels->new_item = 'Guide/Cheat';
    $labels->all_items = 'All Guide/Cheat';
    $labels->view_item = 'View Guide/Cheat';
    $labels->search_items = 'Search Guide/Cheat';
    $labels->not_found = 'No Guides/Cheats found';
    $labels->not_found_in_trash = 'No Guides/Cheats found in Trash';   
}
add_action( 'init', 'change_post_object_label', 999 );

//change menu label of Portfolio in the admin
function change_post_menu_label() {
    global $menu;
    $menu[7][0] = 'Guides/Cheats'; 
}
add_action( 'admin_menu', 'change_post_menu_label' );


//change taxonomy labels
function wpa4182_init()
{
    global $wp_taxonomies;

    $wp_taxonomies['portfolio_category']->labels = (object)array(
        'name' => 'Guide/Cheat Categories',
        'menu_name' => 'Guide/Cheat Categories',
        'singular_name' => 'Guide/Cheat Category',
        'search_items' => 'Search Guide/Cheat Category',
        'popular_items' => 'Popular Guide/Cheat Categories',
        'all_items' => 'All Categories',
        'parent_item' => null, // Tags aren't hierarchical
        'parent_item_colon' => null,
        'edit_item' => 'Edit Category',
        'update_item' => 'Update Category',
        'add_new_item' => 'Add Category',
        'new_item_name' => 'Add Category',
        'separate_items_with_commas' => 'Separate Guide/Cheat Categories with commas',
        'add_or_remove_items' => 'Add or remove Guide/Cheat Category',
        'choose_from_most_used' => 'Choose from the most used Categories',
    );

    $wp_taxonomies['portfolio_category']->label = 'Guide/Cheat Categories';
}
add_action( 'init', 'wpa4182_init',999);

I can't find any part of theme php codes(hook) that typically registers a custom post.So i manage to change the permalinks to something like:

`http://www.mamawithabs.com/portfolio/mauris-pulvinar-nisl-nec-auctor/`

to this:

`http://www.mamawithabs.com/guides/mauris-pulvinar-nisl-nec-auctor/`

I used the code below in executing the redirect:

function modify_portfolio() {
global $wp_post_types;
    $rewrite = &$wp_post_types['portfolio']->rewrite;
    $rewrite['slug'] = 'guides';
}
add_action( 'init', 'modify_portfolio', 999 );

It successfully redirects the link to the desired permalink format but results to 404 error (The page is not found.).

4
  • What code did you use to change the labels? You shouldn't be calling flush_rewrite_rules() on init by the way. That should be run once when needed and not on every load. Jan 16, 2014 at 17:42
  • @NathanDawson: I just added the flush_rewrite_rules() as my last update in my code in functions.php, but still no luck. My post is already updated.
    – Jed
    Jan 17, 2014 at 0:21
  • 1
    Have you considered deregistering the post type instead and re-registering? Just unset from the $wp_post_types global on init. Jan 17, 2014 at 20:09
  • Any code on how to do it correctly?
    – Jed
    Jan 17, 2014 at 21:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.