Support » Themes and Templates » Help with custom image link for ‘the_post_thumbnail’ in functions.php

  • Hi!

    First post. I finally found something I couldn’t figure out by myself. Not strange since this PHP stuff is something I really don’t know.

    Anyway, I’m trying to get functions to work on, say, only ‘page’ or ‘category’, not both.

    I use the new(?), and by my standards awesome, ‘the_post_thumbnail’ function(or what it’s called) to load different sized image attachements depending on where on my blog my visitors are. I’ve got that to work.

    However, since I wan’t things “overly complicated”, I want these thumbnails to link to different things depending on where on my blog they are shown.

    I want images in category “portfolio”, while you are in the main blog feed, to link to the page for the “portfolio” category and when in that category I want them to link to the source image for the post.

    Here’s my ‘functions.php’ content:

    // Use 'the_post_thumbnail()' to attach image to post and easily change size depending on page, category or other.
    if ( function_exists( 'add_theme_support' ) ) { // Load only if wp is up to date
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 457, 257, true ); // Normal post thumbnails
    	add_image_size( 'single_full', 457, 9999 ); // Post page full height images
    	add_image_size( 'special_category', 657, 370, true ); // Styled category thumbnails
    	add_image_size( 'special_category_full_height', 657, 9999 ); // Styled category full heigh images
    	add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 ); // Generate link for attached image (Post Thumbnail)
    	function my_post_image_html( $html, $post_id, $post_image_id ) {
    		$html = '<a href="' . wp_get_attachment_url( $post_image_id ) . '" rel="shadowbox">' . $html . '</a>';
    		return $html;

    Many thanks from a total PHP newbie

  • The topic ‘Help with custom image link for ‘the_post_thumbnail’ in functions.php’ is closed to new replies.