WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a list with a few permalinks which I call to with <a href="<?php echo get_permalink($id); ?>" title=".... And for the title I want to call the_title_attribute(). But it seems it can only be called within a loop, and not by id. How do I correctly get a title attribute?

Note: The reason I want to use the_title_attributes(); is because I use html tags within some of my titles.

share|improve this question
up vote 3 down vote accepted

hey just look in code and it also support fourth parameter post

global $post;    
the_title_attribute(array('post'=>$post));//post object


global $post;
the_title_attribute(array('post'=>$post->ID));//post id

so you can use it like

<a href="<?php echo get_permalink($id); ?>" title="<?php the_title_attribute(array('post'=>$id)); ?>"> //where $id is post id

Important Link


share|improve this answer
The fourth parameter should be used like this: the_title_attribute( array( 'post' => get_post( $id ) ) ); – iEmanuele Aug 28 '13 at 8:49
@iEmanuele hey buddy it also support post id.so we can pass post id to post parameter.please see on code of the_title_attribute – Ravinder Kumar Aug 28 '13 at 9:01
yeah it is true, who knows why, but I thought that the id outside the loop was not of the same post : ) – iEmanuele Aug 28 '13 at 9:10
Nice guys! This works perfectly – Remi Aug 28 '13 at 9:17
@Remi please set "accepted" the Ravs answer, thank you : ) – iEmanuele Aug 28 '13 at 9:30

you can use


to get title by id later you can add html tags like ..

$title_before = " // your html tags";

$title_after = "// your html tags";

$new_title = $title_before .''.get_the_title($ID).''.$title_after;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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