• This is a small patch to properly show featured image in a post if the theme supports it

    in admin/class-cust-li-fi-admin.php, replace the following function

    
    function cust_li_fi_thumbnail_fallback( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
    
            $clink = get_post_meta( get_the_ID(), '_custom_url_image', true );
    
            if ( empty( $html ) || !empty ($clink) && is_singular()) {
                    $width = $size == 'post-thumbnail' ? get_option( 'thumbnail_size_w' ) : NULL;
                    $height = $size == 'post-thumbnail' ? get_option( 'thumbnail_size_h' ) : NULL;
    
                    $html = sprintf(
                            '<a href="%s" title="%s" target="_blank" class="ex-link">%s</a>',
                            $clink,
                            esc_attr( get_the_title( $post_id ) ),
                            empty($html)
                            ? sprintf(
                                    '<img src="%s" style="%s" />',
                                    $clink,
                                    empty($height) && empty($height)
                                    ? 'width: 100%; height: auto; max-width: 100vw'
                                    : sprintf(
                                            '%s%s',
                                            empty($width) ? '' : "width: ${width}px;",
                                            empty($height) ? '' : "height: ${height}px;")
                            )
                            : $html);
            }
            return $html;
    }
    

    also add another hook to the very end of the file

    
    add_action('has_post_thumbnail', function($has_thumbnail = NULL, $post = NULL, $thumbnail_id = NULL) {
            $clink = get_post_meta( get_the_ID(), '_custom_url_image', true );
    
            return !empty($clink);
    });
    

    While this is not ideal, but it gets the job done. Also be careful when you are replacing the function code, as the code itself is rather badly formatted.

    • This topic was modified 4 years, 11 months ago by Jeffrey04.
    • This topic was modified 4 years, 11 months ago by Jeffrey04.
Viewing 1 replies (of 1 total)
  • Hi Jeffrey04:

    How could you put the link only in the featured image of the page or post and in the thumbnails that did nothing?

    What I need is to link to an external url from the highlighted image of a page but when I include that internal page as a thumbnail on another page of the same website that links to the page of the same website, not to the external url.

    I just need to link to an external page since the image highlighted on the page itself is not others.

    Example:

    Here I want link to external url from the featured image
    https://de-senderismo.net/rinoneras/

    Here I not want
    https://de-senderismo.net/prueba-image-custom-link/

    Thanks

    • This reply was modified 4 years, 9 months ago by roman2099.
Viewing 1 replies (of 1 total)
  • The topic ‘Bug fix to show image in post’ is closed to new replies.