• Resolved Energ

    (@energ)


    Hello!

    With such a little PHP knowledge I cannot get this simple code to work. The idea is to get a search engine robot block for all the pages that are blocked by wp-members plugin.

    I am sure some of you will sort this out very quickly. So far I have this:

    //Try to block search engines from blocked pages
    add_filter( 'wpmem_block', 'my_block_function' );
    function my_block_function( $block ) {
    
    	if ($block == true) {
    		add_action('wp_head', 'my_function');
    		function my_function() {
    			echo '<meta name="robots" content="noindex, nofollow">';
    		}
    	}
    
    	return $block;
    }

    Thanks!

    http://wordpress.org/extend/plugins/wp-members/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    That probably won’t work because the wp_head will be completed before the wpmem_block filter. wpmem_block is part of the wpmem_securify process and thus comes during the hook the_content.

    What you would need to do is write a function hooked to wp_head. You need a process to get the post ID so you could use get_post_custom_values to get the block/unblock value.

    Thread Starter Energ

    (@energ)

    Thanks. I noticed that getting custom value didn’t work on posts, so I made it to check if it is one.

    Here it is, if someone needs it too:

    //Add noindex meta tag to blocked pages, posts, blog page and archive page
    add_action('wp_head', 'add_meta_function');
    function add_meta_function() {
    	$values = get_post_custom_values('block');
    	if ($values[0] == true || is_single() || is_home() || is_archive()) {
    		echo '<meta name="robots" content="noindex, nofollow">';
    	}
    }
    Plugin Author Chad Butler

    (@cbutlerjr)

    Actually, get_post_custom_value does work on posts, but you have to pass the
    $post->ID.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Noindex meta tag for blocked pages’ is closed to new replies.