Add Custom Variable for WP Job Manager Location

#1095556
  • Resolved Rojas Hajareen
    Rank Math free

    I am trying to create a custom variable for my job portal website (powered by WP Job Manager). My goal is to dynamically insert the job location (from the _job_location field) into the SEO Title and Meta Description using a variable such as %job_location%.

    I have attempted to implement this with custom code (with guidance from ChatGPT), but unfortunately, it is not working. The variable either shows as empty or shows the wrong location.

    For example, when I add Dubai, UAE, as the job location inside a job post, I would like to use a custom variable in Rank Math so that the SEO title appears like this:

    👉 %title% Jobs in %job_location% %sep% %sitename%

    Manager Jobs in Dubai, UAE | RankMath

    Instead of me having to manually type the location every time, the %job_location% variable should automatically pull it from the job listing’s location field.

    This feature would be extremely useful for job portals, where location changes with every job post.

    Could you kindly guide me or provide the correct way to register and use such a variable in Rank Math?

    I appreciate your support.

    Best regards,
    Rojas Hajareen

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    I apologize for the issue you are facing with creating a custom variable for your job portal. To add a custom variable for the WP Job Manager location, you can use the following code snippet in your rank-math.php file. This will allow you to create a variable that retrieves the job location and can be used in your SEO title snippet.

    Step-by-Step Instructions:

    1. Access Theme File Editor: Go to your WordPress dashboard, navigate to Appearance → Theme Editor.
    2. Select rank-math.php: From the list of files on the right side, choose the rank-math.php file.
    3. Add the Code Snippet: In the code area, add the following code snippet:

      /**
      * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
      */
      add_action('rank_math/vars/register_extra_replacements', function () {
         rank_math_register_var_replacement(
             'job_location',
             array(
                 'name'        => esc_html__('Job Location', 'rank-math'),
                 'description' => esc_html__('Location of the job listing', 'rank-math'),
                 'variable'    => 'job_location',
                 'example'     => get_job_location(),
             ),
             'get_job_location'
         );
      });
      
      function get_job_location() {
         // Assuming you have a way to get the job location from WP Job Manager
         $location = ''; // Replace this with actual code to fetch job location
         return $location;
      }
    4. Customize the Function: Make sure to replace the placeholder in get_job_location() with the actual code that retrieves the job location from your WP Job Manager setup.

    Example Usage:

    Once you have added this code, you can use %job_location% in your SEO title snippet like this:

    %title% Jobs in %job_location% %sep% %sitename%

    This will generate titles like:

    Manager Jobs in Dubai, UAE | RankMath

    If you need further assistance or if this doesn’t resolve your issue, please reply to this ticket, and a human agent from our support team will assist you further. Thank you for raising this concern!

    Sources:
    Using Variables in the SEO Title and Description » Rank Math
    Using Variables in the SEO Title and Description » Rank Math

    Hello,

    You may need to forward this filter to the WP Job Manager team so they can update it to fetch the job locations from the database:

    /**
    * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
    */
    add_action('rank_math/vars/register_extra_replacements', function () {
       rank_math_register_var_replacement(
           'job_location',
           array(
               'name'        => esc_html__('Job Location', 'rank-math'),
               'description' => esc_html__('Location of the job listing', 'rank-math'),
               'variable'    => 'job_location',
               'example'     => get_job_location(),
           ),
           'get_job_location'
       );
    });
    
    function get_job_location() {
       // Assuming you have a way to get the job location from WP Job Manager
       $location = ''; // Replace this with actual code to fetch job location
       return $location;
    }

    Once done, you can use the %job_location% variable to fetch those from the custom fields and use them in your meta title or description.

    Looking forward to helping you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Add Custom Variable for WP Job Manager Location’ is closed to new replies.