This is because the_title()
echos the post title (see the linked documentation). Use get_the_title()
instead which returns the title as a string.
Edit
You have two options:
- Use
get_the_title()
to return, rather than echo, the post title - Filter
the_title
to echo a custom string as the post title
Using get_the_title()
<?php
// NOTE: Inside the Loop,
// or else pass $post->ID
// as a parameter
$post_title = get_the_title();
?>
Using the_title
filter
<?php
function wpse48523_filter_the_title( $title ) {
// Modify or replace $title
// then return the result
// For example, to replace,
// simply return your own value:
// return 'SOME CUSTOM STRING';
//
// Or, you can append the original title
// return $title . 'SOME CUSTOM STRING'
//
// Just be sure to return *something*
return $title . ' appended string';
}
add_filter( 'the_title', 'wpse48523_filter_the_title' );
?>