diff --git a/docs/simplesamlphp-reference-idp-hosted.txt b/docs/simplesamlphp-reference-idp-hosted.txt
index 1c19738089fd5a4e23b7a9fc6f76a59e736b14ed..759c41b8fb66a54fd071d16c14b191157da69ac8 100644
--- a/docs/simplesamlphp-reference-idp-hosted.txt
+++ b/docs/simplesamlphp-reference-idp-hosted.txt
@@ -56,6 +56,8 @@ Common options
 `privacypolicy`
 :   This is an absolute URL for where an user can find a
     privacypolicy. If set, this will be shown on the consent page.
+    `%SPENTITYID%` in the URL will be replaced with the entity id of
+    the service the user is accessing.
 
 :   Note that this option also exists in the SP-remote metadata, and
     any value in the SP-remote metadata overrides the one configured
diff --git a/docs/simplesamlphp-reference-sp-remote.txt b/docs/simplesamlphp-reference-sp-remote.txt
index 6954a00d6250d04a2ca0e753d372c0d95a5206d7..f0cb1979f0820cba5068c714203cac7138c6696c 100644
--- a/docs/simplesamlphp-reference-sp-remote.txt
+++ b/docs/simplesamlphp-reference-sp-remote.txt
@@ -58,6 +58,8 @@ and Shibboleth 1.3 protocol:
 `privacypolicy`
 :   This is an absolute URL for where an user can find a privacypolicy
     for this SP. If set, this will be shown on the consent page.
+    `%SPENTITYID%` in the URL will be replaced with the entity id of
+    this service provider.
 
 :   Note that this option also exists in the IdP-hosted metadata. This
     entry in the SP-remote metadata overrides the option in the
diff --git a/modules/consent/www/getconsent.php b/modules/consent/www/getconsent.php
index d600f09363e3a23c60abc76e1849234894805582..fab2c41aec15e579d4cfb826909c5cebb6f45280 100644
--- a/modules/consent/www/getconsent.php
+++ b/modules/consent/www/getconsent.php
@@ -124,6 +124,10 @@ if (array_key_exists('privacypolicy', $state['Destination'])) {
 } else {
 	$privacypolicy = FALSE;
 }
+if($privacypolicy !== FALSE) {
+	$privacypolicy = str_replace('%SPENTITYID%', urlencode($spentityid),
+		$privacypolicy);
+}
 $t->data['sppp'] = $privacypolicy;