diff --git a/docs/simplesamlphp-reference-idp-remote.txt b/docs/simplesamlphp-reference-idp-remote.txt
index 0ecf9e03a74bb49ff64c72c44b9fa408acd2da11..078b3ce51a1316f9ceb5f5da02976a8d7d9fb6d4 100644
--- a/docs/simplesamlphp-reference-idp-remote.txt
+++ b/docs/simplesamlphp-reference-idp-remote.txt
@@ -111,6 +111,9 @@ The following SAML 2.0 options are available:
     discouraged to do so. For your own safety, please include the string 'http://www.w3.org/2001/04/xmlenc#rsa-1_5' if
     you make use of this option.
 
+`hide.from.discovery`
+:   Whether to hide hide this IdP from the local discovery or not. Set to true to hide it. Defaults to false.
+
 `nameid.encryption`
 :   Whether NameIDs sent to this IdP should be encrypted. The default
     value is `FALSE`.
diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php
index 8b084f315893ad8d3310ec213c0ab2827c1eda28..e93d193a7337452fad0c621f76f6208c21e71e47 100644
--- a/lib/SimpleSAML/XHTML/IdPDisco.php
+++ b/lib/SimpleSAML/XHTML/IdPDisco.php
@@ -448,7 +448,30 @@ class SimpleSAML_XHTML_IdPDisco {
 	protected function getScopedIDPList() {
 		return $this->scopedIDPList;
 	}
-	
+
+
+	/**
+	 * Filter the list of IdPs.
+	 *
+	 * This method returns the IdPs that comply with the following conditions:
+	 *   - The IdP does not have the 'hide.from.discovery' configuration option.
+	 *
+	 * @param array $list An associative array containing metadata for the IdPs to apply the filtering to.
+	 *
+	 * @return array An associative array containing metadata for the IdPs that were not filtered out.
+	 */
+	protected function filter($list)
+	{
+		foreach ($list as $entity => $metadata) {
+			if (array_key_exists('hide.from.discovery', $metadata) && $metadata['hide.from.discovery'] === true) {
+				unset($list[$entity]);
+			}
+		}
+		return $list;
+	}
+
+
+
 	/**
 	 * Handles a request to this discovery service.
 	 *
@@ -487,6 +510,7 @@ class SimpleSAML_XHTML_IdPDisco {
 		/* No choice made. Show discovery service page. */
 
 		$idpList = $this->getIdPList();
+		$idpList = $this->filter($idpList);
 		$preferredIdP = $this->getRecommendedIdP();
 
 		$idpintersection = array_intersect(array_keys($idpList), $this->getScopedIDPList());