0

I have a Wordpress child-themed site at http://mrme.me/utahcountyhiking, and I'm trying to get it so that when you click on the featured image it goes to the associated post. Right now it goes to the media page for the featured image instead of the post.

What I've tried

  • I figured out how to get the child theme to load some JavaScript, but the JS was being run before the PHP added content to the page, so I wasn't able to change things with JS.

  • I tried adding these PHP functions to my child themes functions.php file, but that didn't change anything.

Edit: The featured image is getting set with the Wordpress function wp_get_attachment_link() which returns html containing an image that is linked to the image's attachment page.

The code that sets the featured image is

<?php
    if(get_post_thumbnail_id(get_the_ID())) {
        $besty_featured_image = wp_get_attachment_link( get_post_thumbnail_id(get_the_ID()), 'besty-thumbnail', true ); 
        echo $besty_featured_image;
    }
?>            
    <a href="<?php echo esc_url( get_permalink() ); ?>" class="blog-title"><?php the_title();?></a>
  • Take a look at the according template file(s), it is likely that there you find the piece of code you want to change. Apart from that I voted to close this question, because third party theme support is off-topic on [wordprss.se]. – Nicolai Jun 3 '15 at 13:29
  • If this question isn't allowed here, you can close it, and I'll ask it on Stack Overflow. – wp-overwatch.com Jun 3 '15 at 13:49
  • I can't decide that on my own, the community will decide in time. Consider what I have hinted you to, because there you likely find your solution. – Nicolai Jun 3 '15 at 13:52
  • You posted in your how how it's being set, do you know what file it's pulling from, can you post the full code of it being set? – Howdy_McGee Jun 3 '15 at 16:45
  • @Howdy_McGee I updated the question to show that code. I've also come up with a solution that I've posted as an answer to this question, although the solution doesn't use the child theme, so I'm still open to a better way if someone knows of one, but things are working good enough for me. – wp-overwatch.com Jun 3 '15 at 17:04
2

Theme customisation is off topic however the default themes are exempt so lets look at an example of how its done in Twenty Fifteen.

if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) :
function twentyfifteen_post_thumbnail() {
    if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
        return;
    }

    if ( is_singular() ) :
    ?>

    <div class="post-thumbnail">
        <?php the_post_thumbnail(); ?>
    </div><!-- .post-thumbnail -->

    <?php else : ?>

    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
        <?php
            the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
        ?>
    </a>

    <?php endif; // End is_singular()
}
endif;

You can see this line includes the_permalink and its all wrapped in the <a> tag which links the post thumbnail to the post permalink.

<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
0

Going off of Brad's answer, I was able to fix it by using the following code in the theme's index.html file

<div class="post-box article">
  <a href="<?php echo esc_url( get_permalink() ); ?>" class="blog-title">

    <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) ); ?>
    <div class="myTitleClass"><?php echo the_title(); ?></div>

  </a>
</div>

I do realize it would have been better to use the child theme instead of editing the file directly, but this will work good enough for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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