ThemeShaper Forums » Thematic

[closed]

Help with thematic_create_robots custom filter please. :)

(8 posts)
  • Started 4 years ago by bigtoe
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. bigtoe
    Member

    Hi there.

    I'm trying to modify a "thematic_create_robots" filter and it's not going well.

    Any help would be greatly appreciated.

    I would like to make http://example.com/page/2 and all those paged URLs have a "noindex,follow" robots meta tag, basically, the entire /page/ dir.

    I tried messing around with the ((is_home() && ($paged < 2 )) bits, and it's not working, probably because I'm not very good with php.

    Do I need to create another elseif statement, and how?

    I don't have any SEO plugins installed, and would like to do this with the filter.

    Here's what I have in functions.php for your reference. Thanks in advance.

    function childtheme_create_robots() {
     if((is_home() && ($paged < 2 )) || is_front_page() || is_single() || is_attachment()) {
     $content .= "<meta name=\"robots\" content=\"index,follow\" />";
     } elseif (is_search()) {
     $content .= "<meta name=\"robots\" content=\"noindex,nofollow\" />";
     }
    /*
    elseif (is_page('about-me') {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />";
     }
    */
    else {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />";
     }
        return $content;
    }
    add_filter('thematic_create_robots', 'childtheme_create_robots');

    With the above, I get "index,follow" for everything in /paged/

    Posted 4 years ago #
  2. Hi,

    add global $paged; as first line in your function.

    Chris

    Posted 4 years ago #
  3. bigtoe
    Member

    Hi Chris.

    Thanks for the reply. I did the the following, and I'm still showing "index,follow" for everything in /paged/ from the front page unfortunately.

    No idea what I'm doing wrong. Here's what I have.

    function childtheme_create_robots() {
    global $paged;
     if((is_home() && ($paged < 2 )) || is_front_page() || is_single() || is_attachment()) {
     $content .= "<meta name=\"robots\" content=\"index,follow\" />";
     } elseif (is_search()) {
     $content .= "<meta name=\"robots\" content=\"noindex,nofollow\" />";
     } 
    
    else {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />";
     }
        return $content;
    }
    add_filter('thematic_create_robots', 'childtheme_create_robots');

    Hopefully it's a simple fix. Thanks.

    Posted 4 years ago #
  4. bigtoe
    Member

    Still can't figure this out. Anybody got a minute? Been cracking my head for hours.

    Do I need to modify this ((is_home() && ($paged < 2 ))or is there some other statement I can add to the filter?

    Something like

    elseif "/page/" {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />";
     }

    I tried reversing the < sign, and a bunch of other things that got me syntax errors, but it ended up putting noindex on the front page. Yikes.

    Wish I were decent at php, but it makes my brain hurt.

    Posted 4 years ago #
  5. bigtoe
    Member

    Please sir, may I have some help.

    So I gave this another shot, but apparently I suck.

    Here's what I got, and I'm still getting "index,follow" on "example.com/page/3" etc URLs. I need "noindex,follow".

    function childtheme_create_robots() {
    
     if(is_front_page() || is_single() || is_attachment()) {
     $content .= "<meta name=\"robots\" content=\"index,follow\" />";
     } elseif (is_search()) {
     $content .= "<meta name=\"robots\" content=\"noindex,nofollow\" />";
     } 
    
    elseif (is_paged()) {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />";
     } 
    
    else {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />";
     }
        return $content;
    }
    add_filter('thematic_create_robots', 'childtheme_create_robots');

    Where did I mess up?

    Posted 4 years ago #
  6. bigtoe
    Member

    Figured it out.

    Looks like is_paged() doesn't work standing on its own and needs another conditional with it. And I'm just guessing.

    Thanks for playing wheel of fortune.

    Pasting my filter below so anybody else who wants to copy/use/modify/analyze/obfuscate/clean up/comment/study/port to assembly/delete/discuss it can do so.

    function childtheme_create_robots() {
     if((is_home() && !is_paged()) || (is_front_page() && !is_paged()) || is_single() || is_attachment()) {
     $content .= "<meta name=\"robots\" content=\"index,follow\" />\n\n";
     }
    elseif (is_search()) {
     $content .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n\n";
     }
    else {
     $content .= "<meta name=\"robots\" content=\"noindex,follow\" />\n\n";
     }
        return $content;
    }
    add_filter('thematic_create_robots', 'childtheme_create_robots');
    Posted 4 years ago #
  7. Thompson
    Member

    Update for anyone who stumbles across this as I did when searching. The code above is outdated, but I figured out the current way to modify meta robots:

    // Add noindex to terms/privacy/contact pages
    function my_robots() {
    if (is_page(array(45,142,56))) { //terms,privacy,contact
    echo '<meta name="robots" content="noindex,follow" />';
    }
    else {
    echo '<meta name="robots" content="index,follow" />';
    }
    }
    add_filter('thematic_show_robots', 'my_robots');

    Posted 3 years ago #
  8. seems weird to me. you don't normally echo things out when you are filtering

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.