admin管理员组

文章数量:1122832

I'm using the WP Job Manager plugin in my wordpress website. The list of my jobs is currently found on /jobs . I would like to have it on /careers . The listing of all jobs is not a page so I can't change the url there.

I've found this topic that shows an example on how to change the slug from /job/titlejob to /careers/titlejob. But it doesn't show how I can change /jobs to /careers.

In the example they are doing this:

function change_job_listing_slug( $args ) {
  $args['rewrite']['slug'] = _x( 'careers', 'Job permalink - resave permalinks after changing this', 'job_manager' );
  return $args;
}

add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );

When I add this to my functions.php my job detail pages are found at /careers/jobtitle. But the overview is still on /jobs . How can I change that?

I also tried to change the jobs translation to careers but this also only works for the single job and not for my overview of jobs.

I'm using the WP Job Manager plugin in my wordpress website. The list of my jobs is currently found on /jobs . I would like to have it on /careers . The listing of all jobs is not a page so I can't change the url there.

I've found this topic that shows an example on how to change the slug from /job/titlejob to /careers/titlejob. But it doesn't show how I can change /jobs to /careers.

In the example they are doing this:

function change_job_listing_slug( $args ) {
  $args['rewrite']['slug'] = _x( 'careers', 'Job permalink - resave permalinks after changing this', 'job_manager' );
  return $args;
}

add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );

When I add this to my functions.php my job detail pages are found at /careers/jobtitle. But the overview is still on /jobs . How can I change that?

I also tried to change the jobs translation to careers but this also only works for the single job and not for my overview of jobs.

Share Improve this question edited Apr 9, 2015 at 11:22 nielsv asked Apr 1, 2015 at 16:12 nielsvnielsv 1731 gold badge5 silver badges17 bronze badges 1
  • Please note that questions regarding 3rd-party plugins are considered off-topic within our community. The best place to receive support for such items is the 3rd-party's official support channels. Please review the How to Ask section of our help center to learn more about what questions are on-topic and a good fit at WPD. The question may be brought on-topic by asking it in a more generic, plugin-independent manner. Regardless, I believe I have provided a solution below. – bosco Commented Apr 14, 2015 at 18:26
Add a comment  | 

3 Answers 3

Reset to default 2 +50

If you check out the output() method in the includes/admin/class-wp-job-manager-setup.php file, namely this part:

/**
 * Output addons page
 */
public function output() {
    $step = ! empty( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;

    if ( 3 === $step && ! empty( $_POST ) ) {
        $create_pages    = isset( $_POST['wp-job-manager-create-page'] ) ? $_POST['wp-job-manager-create-page'] : array();
        $page_titles     = $_POST['wp-job-manager-page-title'];
        $pages_to_create = array(
            'submit_job_form' => '[submit_job_form]',
            'job_dashboard'   => '[job_dashboard]',
            'jobs'            => '[jobs]'
        );

        foreach ( $pages_to_create as $page => $content ) {
            if ( ! isset( $create_pages[ $page ] ) || empty( $page_titles[ $page ] ) ) {
                continue;
            }
            $this->create_page( sanitize_text_field( $page_titles[ $page ] ), $content, 'job_manager_' . $page . '_page_id' );
        }
    }

you can see that it's creating a page, with the jobs slug (by default) that contains the [jobs] shortcode to list the available jobs.

So you should be able to simply create a page with the careers slug, that contains the [jobs] shortcode.

Alright, here to help :) If you find this helpful please share the bounty!

Step 1: The Research

My first hint was that these parts of the slugs are usually controlled by custom post type settings, thus I combed through the plugin files - finally finding that in the plugins in the file "class-wp-job-manager-post-types.php" inside the "Includes" folder on line 161, it states (1):

if ( current_theme_supports( 'job-manager-templates' ) ) {
        $has_archive = _x( 'jobs', 'Post type archive slug - resave permalinks after changing this', 'wp-job-manager' );
    } else {
        $has_archive = false;
    }

Step 2: The Change

Now the "current_theme_supports" function gives us an important hint - we need to enable something within the currently active theme for things to work out. A bit of Googling and this is how to do it, straight from the documentation for the plugin (2):

add_theme_support( 'job-manager-templates' );

Simply add this to your theme´s functions.php file. And follow the rest of the instructions in the documentation page referenced above (link below), which include:

  • resaving the permalinks after changing the slug
  • then adding the custom archives and taxonomy templates
  • while I do not have the plugin installed currently this should do the trick

References:

  • (1) https://github.com/mikejolley/WP-Job-Manager/blob/master/includes/class-wp-job-manager-post-types.php
  • (2) https://wpjobmanager.com/document/enabling-full-template-support/

Please Note: Questions regarding 3rd-party plugins and themes are considered off-topic here at the WordPress Development SE. The best place to receive support for such items is the 3rd-party's official support channels. Please review the How to Ask section of our Help Center to learn more about what questions are on-topic and a good fit.


That said, I took a glance at the plugin, in particular the file includes/class-wp-job-manager-post-types.php where the plugin actually registers the 'job_listing' post-type. The plugin author supplies the 'register_post_type_job_listing' filter hook in such a manner that you can alter any and every argument to the custom post-type's registration.

Keeping that in mind, reading the Codex entry for register_post_type(), take note of the has_archive argument, which allows you to specify which slug to use for archive pages. The most direct solution, then, should be to update the function in your theme's functions.php file to something similar to the following:

function wpse182946_change_job_listing_slugs( $args ) {
  $args['rewrite']['slug'] = _x( 'career', 'Job CPT slug', 'my_site_identifier' );
  $args['has_archive']     = _x( 'careers', 'Job CPT archive slug', 'my_site_identifier' );

  return $args;
}

add_filter( 'register_post_type_job_listing', 'wpse182946_change_job_listing_slugs' );

Manually flush your installation's rewrite rules by saving your permalink settings on the Dashboard in order for the changes to take effect.

If you wished to change the text every (or just a few) place it appears on the site, you should additionally alter the labels array argument:

function wpse182946_modify_job_listing_cpt( $args ) {
  $singular = 'Career';
  $plural   = 'Careers';

  // Alter URL permalinks/slugs
  $args['rewrite']['slug'] = _x( strtolower( $singular ), 'Job CPT slug', 'my_site_identifier' );
  $args['has_archive']     = _x( strtolower( $plural ), 'Job CPT archive slug', 'my_site_identifier' );

  // Alter CPT labels
  $args['labels']['name']                = $plural;
  $args['labels']['singular_name']       = $singular;
  $args['labels']['menu_name']           = __( $singular . ' Listings', 'my_site_identifier' );
  $args['labels']['all_items']           = __( 'All ' . $plural, 'my_site_identifier' );
  $args['labels']['add_new']             = __( 'Add New', 'my_site_identifier' );
  $args['labels']['add_new_item']        = __( 'Add ' . $singular, 'my_site_identifier' );
  $args['labels']['edit']                = __( 'Edit', 'my_site_identifier' );
  $args['labels']['edit_item']           = __( 'Edit ' . $singular, 'my_site_identifier' );
  $args['labels']['new_item']            = __( 'New ' . $singular, 'my_site_identifier' );
  $args['labels']['view']                = __( 'View ' . $singular, 'my_site_identifier' );
  $args['labels']['view_item']           = __( 'View ' . $singular, 'my_site_identifier' );
  $args['labels']['search_items']        = __( 'Search ' . $plural, 'my_site_identifier' );
  $args['labels']['not_found']           = __( 'No ' . $plural . ' found', 'my_site_identifier' );
  $args['labels']['not_found_in_trash']  = __( 'No ' . $plural . ' found in trash', 'my_site_identifier' );
  $args['labels']['parent']              = __( 'Parent ' . $singular, 'my_site_identifier' );

  return $args;
}

add_filter( 'register_post_type_job_listing', 'wpse182946_modify_job_listing_cpt' );

本文标签: pluginsWP Job Manger change jobs url (NOT slug)