- AuthorPosts
- November 13, 2016 at 17:33 #8010
DawnParticipantI 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!
November 14, 2016 at 01:22 #8019
RattusKeymasterAdd 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).November 14, 2016 at 06:04 #8027
DawnParticipantDoes this also involved Googlebots, etc.?
November 14, 2016 at 11:48 #8035
RattusKeymasterTo 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');April 8, 2017 at 01:32 #9284
reneechristine83ParticipantThis will work on galleries as well as long as they’re renamed correctly?
Thanks,
ReneeApril 8, 2017 at 21:42 #9288
RattusKeymaster@reneechristine83: Yes, but for galleries you should prepend ‘exclude_’ string to the Slug field.
April 13, 2017 at 01:34 #9317
reneechristine83ParticipantFollowup 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,
ReneeJune 16, 2017 at 23:15 #9659
reneechristine83ParticipantFor 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.
- AuthorPosts
- The forum ‘Gmedia Gallery WordPress Plugin’ is closed to new topics and replies.
