© 2021 Greatives Hub - Powered by Greatives & Greatives Web

Rename Portfolio

Landing Forums Somentra (Impeka) Feedback Rename Portfolio

  • Creator
    Topic
  • #427
    hiegl
    Participant

    Hi, what would you recommend, if we need to rename the portfolio CPT? We want to call it “people” for our editors. Is there an easy way for this?
    Thanks,
    Bernhard

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #428
    Marius1989
    Participant
    Hub Member Badge

    Are you talking about the backend menu item?
    If so, do you only want to rename it for the editor role?

    A general solution could be something like this:

    function wd_admin_menu_rename() {
         global $menu;
         $menu[6][0] = 'People';
    }
    add_action( 'admin_menu', 'wd_admin_menu_rename' );

    Paste this to the functions.php inside your child theme.
    Hope this is what you were looking for.

    #429
    hiegl
    Participant
    Hub Member Badge
    Collector Badge Lvl 1

    Thanks Marius!
    I need to rename all of the related backend menu/submenu items, so that my client can use this CPT without having to deal with the term portfolio at all. I guess there are plugins for this, but a solution via functions.php would be better.

    An alternative would be to add a new CPT instead of reusing the portfolio. What would be your recommendation for adding new CPTs, while retaining Impekas features?

    #430
    Marius1989
    Participant
    Hub Member Badge

    Also not a big fan of plugins when little code can do the job.
    Is the people CPT the only CPT you need for this project? If so, I would just use the portfolio one.
    I always do that in such a case in my projects, if only one CPT is needed.

    If you want I can quickly send you a code snippet. Just tell me exactly what you want. The more details, the better.

    #431
    Marius1989
    Participant
    Hub Member Badge

    Alright, I quickly threw something together:

    function give_your_function_a_custom_name_or_whatever() {
      global $menu; // set a global to get the wp admin menu array
      global $submenu; // set a global to get access to the submenu array
    
      $menu[6][0] = 'People'; // change "Portfolio" to "People"
      $menu[6][6] = 'dashicons-businessperson'; // change icon, you can pick another one that fits your needs more here: https://developer.wordpress.org/resource/dashicons/
      $submenu['edit.php?post_type=portfolio'][5][0] = 'Overview'; // change "Portfolio Items" to "Overview"
      $submenu['edit.php?post_type=portfolio'][10][0] = 'Add Person'; // change "Add New" to "Add Person"
      $submenu['edit.php?post_type=portfolio'][15][0] = 'People Fields'; // change "Portfolio Categories" to "People Categories"
      $submenu['edit.php?post_type=portfolio'][16][0] = 'People Categories'; // change "Portfolio Fields" to "People Fields"
    }
    add_action( 'admin_menu', 'give_your_function_a_custom_name_or_whatever' );

    If you want the changes only on the editor role appear, wrap the above code inside the following one:

    if (current_user_can('editor')) {
      
    //here goes the code from above
    
    } 

    Tell me if there is anything else you still need.

    #432
    Marius1989
    Participant
    Hub Member Badge

    PS: You can always check the menu items array inside the wp admin dashboard for further modification. Just paste this inside your functions.php temporarily. It only will affect your backend.

    Having this simple overview makes it quite easy to make required changes to specific areas.

    if (!function_exists('debug_admin_menus')):
      function debug_admin_menus() {
          global $submenu, $menu, $pagenow;
          if ( current_user_can('manage_options') ) { // enable for admin role
              if( $pagenow == 'index.php' ) {  // puts the menu array list inside the WP admin dashboard
                  echo '<pre>'; print_r( $menu ); echo '</pre>'; // main menu items
                  echo '<pre>'; print_r( $submenu ); echo '</pre>'; // submenu items
              }
          }
      }
      add_action( 'admin_notices', 'debug_admin_menus' );
      endif;  
    #433
    hiegl
    Participant
    Hub Member Badge
    Collector Badge Lvl 1

    Thanks Marius, I will try these code snippets. Will probably take some time though.

    Btw. what is your preference, if we have to create several new CPT? Would you go with a plugin (which one) then or use custom code as well?

    #434
    Marius1989
    Participant
    Hub Member Badge

    I prefer to create new CPT’s with custom functions, since it is really easy and avoids all unnecessary bloat most plugins bring along.

    If you want to go the plugin route, “Custom Post Type UI” could be the one you are looking for.

    No matter what, both solutions are summarized pretty well in the following article:
    wpbeginner DOT com/wp-tutorials/how-to-create-custom-post-types-in-wordpress/

    I recommend to have a look into the code of Impeka and check how the team integrated the CPT’s inside the theme so you there is just a very small chance of making errors by replicating this procedure.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Privacy Preferences

When you visit our website, it may store information through your browser from specific services, usually in the form of cookies. Here you can change your Privacy preferences. It is worth noting that blocking some types of cookies may impact your experience on our website and the services we are able to offer.

Our website uses cookies, mainly from 3rd party services. Define your Privacy Preferences and/or agree to our use of cookies.