• Hi, I use has_post_thumbnail() to output custom sized images into slider. Uunfortunatley has_post_thumbnail() outputs array of attirbutes but i need URL only. So I used

    <?php
    $domsxe = simplexml_load_string(get_the_post_thumbnail());
    $thumbnailsrc = $domsxe->attributes()->src;
    ?>

    And it worked great exept when I’m calling it in the loop below it outputs thumbnail image 150×150 instead of my custom-sized image ‘slider’.

    <?php if (has_post_thumbnail()){ ?>
    <?php
    $domsxe = simplexml_load_string(get_the_post_thumbnail());
    $thumbnailsrc = $domsxe->attributes()->src;
    ?>
    
    <li class="sliderImage">
                    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <img src="<?php echo $thumbnailsrc ?>" alt="<?php the_title() ?>" width="560" height="229" />
    
    </a>

    If I use has_post_thumbnail(‘slider’) withing the loop instead of defining it as a $thumbnailsrc above, then I’m getting the deisred image, but them with the image i’m getting all other attribs like with, alt etc and I don’t need it.
    Any help is greatly appreciated.

Viewing 1 replies (of 1 total)
  • Works for me in Facebook Open Graph Protocol Meta Tag.

    Thanks

    <meta property="og:image" content="<?php if (has_post_thumbnail()){ $domsxe = simplexml_load_string(get_the_post_thumbnail($id, 'thumbnail')); $thumbnailsrc = $domsxe->attributes()->src; echo $thumbnailsrc; } ?>" />

Viewing 1 replies (of 1 total)
  • The topic ‘has_post_thumbnail() need to output URL only’ is closed to new replies.