diff --git a/inc/template.php b/inc/template.php
index c1848dd79b1d6a4beda80fd526e2c472b18ba9f0..64c87d58395b2b55fd72ec37d06563dd518e381a 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -815,14 +815,14 @@ function tpl_mediauploadform(){
 }
 
 /**
- * Prints the name of the given page (current one if none given).
+ * Prints or returns the name of the given page (current one if none given).
  *
  * If useheading is enabled this will use the first headline else
- * the given ID is printed.
+ * the given ID is used.
  *
  * @author Andreas Gohr <andi@splitbrain.org>
  */
-function tpl_pagetitle($id=null){
+function tpl_pagetitle($id=null, $ret=false){
   global $conf;
   if(is_null($id)){
     global $ID;
@@ -834,7 +834,12 @@ function tpl_pagetitle($id=null){
     $title = p_get_first_heading($id);
     if ($title) $name = $title;
   }
-  print hsc($name);
+
+  if ($ret) {
+      return hsc($name);
+  } else {
+      print hsc($name);
+  }
 }
 
 /**
diff --git a/lib/tpl/default/main.php b/lib/tpl/default/main.php
index 25f0cb3ffd80e8dc21d91e1cc90a60aa02c5f16e..a63831ae43fb8588d5e2a2c66ce54fb6e2ead07c 100644
--- a/lib/tpl/default/main.php
+++ b/lib/tpl/default/main.php
@@ -36,7 +36,7 @@
 
     <div class="header">
       <div class="pagename">
-        [[<?php tpl_link(wl($ID,'do=backlink'),$ID)?>]]
+        [[<?php tpl_link(wl($ID,'do=backlink'),tpl_pagetitle($ID,true))?>]]
       </div>
       <div class="logo">
         <?php tpl_link(wl(),$conf['title'],'name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[ALT+H]"')?>