I've added the privatemsg module send message form in a php block, it's working fine but the page tittle and the metatag tittle now shows "write a new message to(user uid)" instead of the node tittle.

this is the code in the php block:

 $node = node_load(arg(1));
 $recipients = strip_tags($node->uid);
 $subject = 'custom subject';
 print '<div class="custom-msg">';
 print drupal_render(drupal_get_form('privatemsg_new', recipients,         
 print "</div>";`

I can't figure out why this could be happening, i'm new to Drupal.

Thank you.


I've created a custom module as @burnsjeremy suggested, it works but the same error is happening. Check the comment line in the code.

function seb_privatemsg_block_info(){
    $block['seb_msg'] = array(
       'info' => t('Seb Private Msg'),
       'cache' => DRUPAL_NO_CACHE
    return $block;
* Implements hook_block_view().
function seb_privatemsg_block_view($delta = '') {
    $block = array();
    $block['subject'] = '';
    $block['content'] = seb_privatemsg_content();
    return $block;
function seb_privatemsg_content() {  
    $node = node_load(arg(1));
    $recipient = strip_tags($node->uid);
    $subject = 'custom subject';
    $output = '';
    // if i comment the following line the title is correct
    $output .= drupal_render(drupal_get_form('privatemsg_new', $recipient, $subject));
    return $output;

Any help would be greatly appreciated.

  • Why are loading a node? It's not getting used in the code you have shown but it could be messing with something in the processing of the Drupal page. The documentation is here: drupal.org/node/624528 for more information. Although I really don't like the way this code is put together, placing this code in a custom module and rendering the block in code would be much better. Nov 8, 2015 at 22:09
  • @burnsjeremy i've Updated my question after placing the code in a custom module as you suggested, but still no luck. can you take a look please?
    – Sebweb
    Nov 9, 2015 at 0:49
  • I added an answer below, I would keep the custom module block code, it's much better than using the PHP filter and more secure also. Just wanted to throw that into the comments here :) Nov 9, 2015 at 1:24

1 Answer 1


So I found an issue about this in the privatemsg issue queue, basically they are overwriting the page title when the form is embedded like this. So you need to use the code below to save the title before the form call and then set the title back to the saved one afterwards.

// Save the title.
$stored_title = drupal_set_title();
// Call the form.
print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject));
// Set title back to the saved version.

Here is the link to the issue if you want to do more research: https://www.drupal.org/node/1621198

  • Awesome! Glad it helped, don't forget to mark as correct Nov 9, 2015 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.