0

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?

0

1 Answer 1

2

Try 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,
    ) );
}
?>

Your Answer

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

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