diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php
index 631865a9f78bc54f92be95f62b6ac48e0f3f4b59..f5b89765706f51e0f57e36ea463600b420cf38d7 100644
--- a/www/saml2/idp/metadata.php
+++ b/www/saml2/idp/metadata.php
@@ -136,6 +136,15 @@ try {
 
 	if ($idpmeta->hasValue('EntityAttributes')) {
 		$metaArray['EntityAttributes'] = $idpmeta->getArray('EntityAttributes');
+
+		// check for entity categories
+		$entity_category = 'http://macedir.org/entity-category';
+		$hide_from_discovery = 'http://refeds.org/category/hide-from-discovery';
+		if (array_key_exists($entity_category, $metaArray['EntityAttributes'])) {
+			if (in_array($hide_from_discovery, $metaArray['EntityAttributes'][$entity_category])) {
+				$metaArray['hide.from.discovery'] = true;
+			}
+		}
 	}
 
 	if ($idpmeta->hasValue('UIInfo')) {