• Resolved lilimatourne

    (@lilimatourne)


    Hello!

    I am trying to add a custom code custom code using the Yoast developer filter wpseo_robots that will make my Yoast SEO plugin automatically set expired job pages to ‘noindex’.

    I’ve been told to look at this code example to see how the filter can be used, and I’ve tried to add this:

    add_filter( ‘wpseo_robots’, ‘yoast_seo_robots_remove_single’ );

    function yoast_seo_robots_remove_single( $robots ) {
    if ( job_is_Expired ) {
    return ‘noindex,nofollow’;
    } else {
    return $robots;
    }
    }

    but it is not working – as I don’t know what condition I should be putting in the ‘if’

    I was wondering if anyone would be able to help me with this.

    Thanks a lot!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi @lilimatourne,

    Thank you for reaching out. The gist you are referring to on GitHub is an older one and might not work with the latest releases of Yoast SEO, specifically release 14 and above. We encourage you to take a look at our metadata API explained in detail on developer.yoast.com here: https://developer.yoast.com/customization/apis/metadata-api.

    Please do know that we can’t give support on a specific code for your site or customization as it might be unique to your site/configuration and we don’t want to suggest incorrect or incomplete code. Thanks!

    Thread Starter lilimatourne

    (@lilimatourne)

    Thanks a lot for your response @jeroenrotty

    And may I ask, how can I test to see if this issue is resolved?

    Here is how I am currently doing it, and I wanted to check if this is correct.

    Everytime I try a new custom code, I test to see if it works by going through the following steps.

    I go to an active job, and check that “Allow search engines to show this Job in search results?” is set to: “yes, current default for jobs”.

    Then I set that job as expired.

    I refresh the page, and I check that “Allow search engines to show this Job in search results?” is set to: “no”

    Therefore, I expect to see the expired job automatically set to “no” if the custom code worked – and I wanted to check with you if that assumption is correct.

    Will I be able to check in that way that the fix worked? If no, how can I test this code?

    Hi @lilimatourne,

    Thanks for the details. What you’d like to achieve setting the expired job robots value automatically after they expire is possible using the developer hooks mentioned in the Yoast SEO metadata API.

    The problem you’re seeing in your code example is due to two things: 1.) using the wrong code format (Sorry for sending and outdated code example!) and 2.) the condition in the if statement isn’t valid. You’ll need to use WordPress conditional tags based on the post type or date, for example, that will only affect the desired pages.

    We recommend testing any custom code that you add on a staging site to avoid causing errors your production site. Your hosting provider may be able to set one up for you.

    If you’re not familiar with what custom code to add or how to use WordPress or Yoast SEO hooks, we highly recommend contacting a web developer who can look at the details of your specific site.

    Thread Starter lilimatourne

    (@lilimatourne)

    Thanks a lot for the information @priscillamc

    What I meant regarding the testing, was what behaviour should I be expecting to show me that the customised code is working in this case – and that expired job listings are indeed no longer showing un in SERP?

    I.e. will the “Allow search engines to show this Job in search results?” be set to “no” automatically once a job is expired?

    Or is there another way to see that this customised code is working?

    Plugin Support Michael Ti?a

    (@mikes41720)

    Hi,

    Just to clarify, with the custom code that you’ve put in place, you just want to clarify if it’s working as expected?

    Well, if a job is active, and the setting of ‘allow search engines to show this job in search results?’ is set to ‘yes’ which means that it will output a meta robots tag of ‘index’ and will tell the search engines that it should be showing in the search results.

    and then you set it to expired, and the setting of ‘allow search engines to show this job in search results?’ is set to ‘no, this means it will output a meta robots tag of ‘noindex’ and will tell the search engines that it should not be showing in the search results.

    If that’s the expected outcome, then that sounds like it’s working correctly for your use-case.

    Thread Starter lilimatourne

    (@lilimatourne)

    Thank you for your response @mikes41720

    I have added this custom code:

    if( ! function_exists( ‘yoast_seo_robots_remove_single_job_expired’ ) ) {
    function yoast_seo_robots_remove_single_job_expired( $robots ) {
    if( is_singular( ‘job_listing’ ) && get_post_status() == ‘expired’ ) {
    return ‘noindex,nofollow’;
    } else {
    return $robots;
    }
    }
    }
    add_filter( ‘wpseo_robots’, ‘yoast_seo_robots_remove_single_job_expired’ );

    Then I manually set a live job to ‘expired’, then checked in the job listing: and the setting of ‘allow search engines to show this job in search results?’ was still set to ‘yes, current default for jobs’- therefore I take it this custom code did not work

    Do you have any advice on this for me please?

    Thanks a lot

    Plugin Support devnihil

    (@devnihil)

    @lilimatourne Unfortunately we can’t offer any additional support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

    Plugin Support devnihil

    (@devnihil)

    We are going ahead and marking this issue as resolved due to inactivity. If you require any further assistance please create a new issue.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘noindex expired job listings’ is closed to new replies.