Using this code:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail("mini-me", array(
'class' => 'x-img smpic x-img-circle',
'alt' => the_title(),
'title' => the_title()
));
}
?>
However, alt and title are being output as text on website instead of enclosed tags. What should the syntax be instead?
Using this code:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail("mini-me", array(
'class' => 'x-img smpic x-img-circle',
'alt' => the_title(),
'title' => the_title()
));
}
?>
However, alt and title are being output as text on website instead of enclosed tags. What should the syntax be instead?
Share Improve this question edited Feb 24, 2018 at 10:47 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 23, 2018 at 16:44 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges 01 Answer
Reset to default 2Try using get_the_title
instead of the_title
- from the Function Reference:
the_title
- Display or retrieve the current post title with optional markup.get_the_title
- Retrieve post title.
You might notice that the_title
says "Display or retrieve" - and it's true, you can pass false
to the third parameter of the_title
to get it's output as a return value instead of it echo
'ing directly to the page, i.e.
$mytitle = the_title( '', '', false );
EDIT: Updated your code to show this in action:
<?php
if ( has_post_thumbnail() ) {
$title = get_the_title();
the_post_thumbnail("mini-me", array(
'class' => 'x-img smpic x-img-circle',
'alt' => $title,
'title' => $title,
) );
}
?>