Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #8010
    Dawn
    Participant

    I want to “hide” from search engines the individual item posts created in Gmedia and rely on the overlay for displaying them. Is there a way to do so?

    Thank you!

    #8019
    Rattus
    Keymaster

    Add code below to your theme functions.php file:

    function search_exclude_by_post_name( $search, $wp_query ){
        global $wpdb;
        if ( empty( $search ) )
            return $search; // skip processing - no search term in query
        $name_like = 'exclude_';
        $search .= " AND ($wpdb->posts.post_name NOT LIKE '{$name_like}%')";
        return $search;
    }
    add_filter( 'posts_search', 'search_exclude_by_post_name', 500, 2 );

    Now you can select Gmedia items -> click Action -> Batch Edit -> Edit filename -> set something like ‘exclude_{filename}’ and apply.
    All Gmedia items with ‘exclude_’ in the name will be skipped from search. (Note: posts with permalink name started with ‘exclude_’ will be skipped too).

    #8027
    Dawn
    Participant

    Does this also involved Googlebots, etc.?

    #8035
    Rattus
    Keymaster

    To exclude search bots you can add to your theme function.php:

    function gmedia_post_noindex(){
        global $post;
        if(is_single() && 'gmedia' == substr($post->post_type, 0, 6)){
            global $gmDB;
            if('gmedia' == $post->post_type){
                $obj_id   = get_post_meta($post->ID, '_gmedia_ID', true);
            } else{
                $obj_id   = get_post_meta($post->ID, '_gmedia_term_ID', true);
            }
            $noindex = $gmDB->get_metadata('gmedia', $obj_id, 'noindex', true);
            if($noindex){
                echo '<meta name="robots" content="noindex,nofollow" />';
            }
        }
    }
    add_action('wp_head', 'gmedia_post_noindex');

    Then add custom field “noindex” with any value to Gmedia items which you want to exclude from indexing.

    OR

    you can add code below to automatically exclude from indexing any posts which have ‘exclude_’ in the name:

    function noindex_by_post_name(){
        global $post;
        if(is_single() && 'exclude_' == substr($post->post_name, 0, 8)){
            echo '<meta name="robots" content="noindex,nofollow" />';
        }
    }
    add_action('wp_head', 'noindex_by_post_name');
    #9284
    reneechristine83
    Participant

    This will work on galleries as well as long as they’re renamed correctly?
    Thanks,
    Renee

    #9288
    Rattus
    Keymaster

    @reneechristine83: Yes, but for galleries you should prepend ‘exclude_’ string to the Slug field.

    #9317
    reneechristine83
    Participant

    Followup question that may be too complicated – Is there a way to make gallery images pop up in a website’s search in the same way a feature image pops up next to a post or page?
    Thanks,
    Renee

    #9659
    reneechristine83
    Participant

    For anyone who uses this, be aware that appending any individual images… I decided to go in and exclude all of my images from search. Only problem is that if I have used any of those images on pages, it breaks them.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Gmedia Gallery WordPress Plugin’ is closed to new topics and replies.
Forum closed. Use forum at Wordpress.org: Gmedia Support Forum