| 5 path.inc | drupal_set_title($title = NULL) |
| 6 path.inc | drupal_set_title($title = NULL) |
| 7 bootstrap.inc | drupal_set_title($title = NULL, $output = CHECK_PLAIN) |
| 8 bootstrap.inc | drupal_set_title($title = NULL, $output = CHECK_PLAIN) |
Set the title of the current page, for display on the page and in the title bar.
Parameters
$title: Optional string value to assign to the page title; or if set to NULL (default), leaves the current title unchanged.
Return value
The updated title of the current page.
58 calls to drupal_set_title()
File
- includes/
path.inc, line 206 - Functions to handle paths in Drupal, including path aliasing.
Code
function drupal_set_title($title = NULL) {
static $stored_title;
if (isset($title)) {
$stored_title = $title;
}
return $stored_title;
}
Login or register to post comments
Comments
$title is interpreted as HTML
Beware: $title is interpreted as HTML. If you have plaintext strings such as for example $node->title, you must escape them with check_plain or use the correct placeholder in t() before passing them to drupal_set_title(). If you don't, users can execute a cross site scripting attack against your site.
<?php
// Incorrect:
drupal_set_title($node->title);
drupal_set_title(t('Foo !title', array('!title' => $node->title)));
// Correct:
drupal_set_title(check_plain($node->title));
drupal_set_title(t('Foo @title', array('@title' => $node->title)));
drupal_set_title(t('Foo %title', array('%title' => $node->title)));
?>
If you have user supplied HTML that must be passed to drupal_set_title, filter it so it contains only harmless tags:
<?php
// Incorrect:
drupal_set_title($user_supplied_html);
// Correct:
drupal_set_title(filter_xss($user_supplied_html));
?>
current page url and title for social sharing
I want to provide social share with link to most popular bookmarking site, for the purpose of performance improvement I don't link to use any social share/link modules instead I want to used only one image and linking it with various social sites using html image map tag and link code similar to the below one.
Twitter: http://twitter.com/home?status=[TITLE]+[URL]
Facebook: http://www.facebook.com/share.php?u=[URL]&title=[TITLE]
StumbleUpon: http://www.stumbleupon.com/submit?url=[URL]&title=[TITLE]
Delicious: http://del.icio.us/post?url=[URL]&title=[TITLE]]¬es=[DESCRIPTION]
Google Buzz: http://www.google.com/reader/link?title=[TITLE]&url=[URL]
Linkedin: http://www.linkedin.com/shareArticle?mini=true&url=[URL]&title=[TITLE]&source=[SOURCE/DOMAIN]
But I am not know how to get drupal current node url and node title and what to replace [URL] and [TITLE] in the above said social share link urls.
I tried to place the above code in page.tpl.php by replacing [URL] with $url and [TITLE] with $title and that is not useful to fetch the actual url and title from the node.
I thank you for your valuable helps in this regard.
Have you tried...
Have you tried :
print $node->title; // node titleprint url($node_url, array('absolute' => TRUE)); // for url
However, you should put this in node.tpl.php because page.tpl.php may contain many nodes in some cases.
T.
change whole title
when i use the drupal_set_title to set the title to "123 abc" it sets the title as: "123 abc | Site Name" is there any way to avoid this?
yes
check out page.tpl.php in your theme -- in the title attribute you're probably also printing the site name.
or you might be using $head_title -- which also has the site name in it. check out this thread: http://drupal.org/node/77522