Skip to content

Snippet: Hide portfolio media block on password protected posts

// Hide portfolio media block on password protected posts
add_filter( 'totaltheme/portfolio/single_blocks', function( $blocks, $instance ) {

	// Don't mess with customizer blocks
	if ( 'customizer' == $instance ) {
		return $blocks;
	}

	// Alter front-end blocks
	else {

		// Get list of active blocks
		$blocks = array_combine( $blocks, $blocks );

		// Remove media for password procted posts
		if ( isset( $blocks['media'] ) && post_password_required() ) {
			unset( $blocks['media'] );
		}

	}

	// Return blocks
	return $blocks;

}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top