Wrong featured image links
-
I have a problem showing only on live site while everything works fine on localhost. The problem is not a migration problem because it’s present also on a site set up directly on the live domain.
In the image source before the WordPress featured image links are attached paths containing reference to the physical mounted storage that are not part of the correct link.
I’ve set up a demo on http://biro.name:
There is a WordPress Featured Image not showing because the link of the image is:
http://biro.name/wp-content/home43b/sub001/sc27622-OTFB/biro.name/wp-content/uploads/2014/12/Rome-city-Wallpaper.jpgThe part:
“http://biro.name/wp-content/home43b/sub001/sc27622-OTFB/”
should not be there. Without this the link would be correct:
http://biro.name/wp-content/uploads/2014/12/Rome-city-Wallpaper.jpgCan anybody suggest me how to fix the problem?
Thank you for your attention!
-
Could you please paste your “index.php” (or whatever contains get_the_post_thumbnail function) here?
It’s not in the index.php. It’s in wp-includes/post-thumbnail-template.php (I found searching for it in a downloaded copy):
<?php /** * WordPress Post Thumbnail Template Functions. * * Support for post thumbnails * Themes function.php must call add_theme_support( 'post-thumbnails' ) to use these. * * @package WordPress * @subpackage Template */ /** * Check if post has an image attached. * * @since 2.9.0 * * @param int $post_id Optional. Post ID. * @return bool Whether post has an image attached. */ function has_post_thumbnail( $post_id = null ) { return (bool) get_post_thumbnail_id( $post_id ); } /** * Retrieve Post Thumbnail ID. * * @since 2.9.0 * * @param int $post_id Optional. Post ID. * @return int */ function get_post_thumbnail_id( $post_id = null ) { $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; return get_post_meta( $post_id, '_thumbnail_id', true ); } /** * Display Post Thumbnail. * * @since 2.9.0 * * @param string|array $size Optional. Image size. Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );. * @param string|array $attr Optional. Query string or array of attributes. */ function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { echo get_the_post_thumbnail( null, $size, $attr ); } /** * Update cache for thumbnails in the current loop * * @since 3.2.0 * * @param object $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. */ function update_post_thumbnail_cache( $wp_query = null ) { if ( ! $wp_query ) $wp_query = $GLOBALS['wp_query']; if ( $wp_query->thumbnails_cached ) return; $thumb_ids = array(); foreach ( $wp_query->posts as $post ) { if ( $id = get_post_thumbnail_id( $post->ID ) ) $thumb_ids[] = $id; } if ( ! empty ( $thumb_ids ) ) { _prime_post_caches( $thumb_ids, false, true ); } $wp_query->thumbnails_cached = true; } /** * Retrieve Post Thumbnail. * * @since 2.9.0 * * @param int $post_id Optional. Post ID. * @param string $size Optional. Image size. Defaults to 'post-thumbnail'. * @param string|array $attr Optional. Query string or array of attributes. */ function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) { $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; $post_thumbnail_id = get_post_thumbnail_id( $post_id ); /** * Filter the post thumbnail size. * * @since 2.9.0 * * @param string $size The post thumbnail size. */ $size = apply_filters( 'post_thumbnail_size', $size ); if ( $post_thumbnail_id ) { /** * Fires before fetching the post thumbnail HTML. * * Provides "just in time" filtering of all filters in wp_get_attachment_image(). * * @since 2.9.0 * * @param string $post_id The post ID. * @param string $post_thumbnail_id The post thumbnail ID. * @param string $size The post thumbnail size. */ do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); if ( in_the_loop() ) update_post_thumbnail_cache(); $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); /** * Fires after fetching the post thumbnail HTML. * * @since 2.9.0 * * @param string $post_id The post ID. * @param string $post_thumbnail_id The post thumbnail ID. * @param string $size The post thumbnail size. */ do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); } else { $html = ''; } /** * Filter the post thumbnail HTML. * * @since 2.9.0 * * @param string $html The post thumbnail HTML. * @param string $post_id The post ID. * @param string $post_thumbnail_id The post thumbnail ID. * @param string $size The post thumbnail size. * @param string $attr Query string of attributes. */ return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr ); }No I mean one of your theme’s files which call this function. Anyway. If you are not using static front page, please copy and past your “index.php” and if so, the “page.php”
Thank you, Morteza!
This demo is not using a static homepage (but with a static homepage I’ve got the same results).
The website is using RocketTheme’s RokSprocket Mosaic Layout wich is set to show the page’s Featured Image (wich work works perfectly on my localhost).
The index.php:
<?php /** * Front to the WordPress application. This file doesn't do anything, but loads * wp-blog-header.php which does and tells WordPress to load the theme. * * @package WordPress */ /** * Tells WordPress to load the WordPress theme and output it. * * @var bool */ define('WP_USE_THEMES', true); /** Loads the WordPress Environment and Template */ require( dirname( __FILE__ ) . '/wp-blog-header.php' );The page.php:
<?php /** * @version 1.0 May 14, 2013 * @author RocketTheme http://www.rockettheme.com * @copyright Copyright (C) 2007 - 2013 RocketTheme, LLC * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only */ // no direct access defined( 'ABSPATH' ) or die( 'Restricted access' ); ?> <?php global $post, $posts, $query_string; ?> <div class="item-page"> <?php if ( have_posts() ) : ?> <?php /** Begin Page Heading **/ ?> <?php if( $gantry->get( 'page-page-heading-enabled', '0' ) && $gantry->get( 'page-page-heading-text' ) != '' ) : ?> <h1> <?php echo $gantry->get( 'page-page-heading-text' ); ?> </h1> <?php endif; ?> <?php /** End Page Heading **/ ?> <?php while ( have_posts() ) : the_post(); ?> <?php $this->gantry_get_template_part( 'content/content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) ); ?> <?php endwhile; ?> <?php else : ?> <h1> <?php _re('Sorry, no pages matched your criteria.'); ?> </h1> <?php endif; ?> </div>You have to look for thumbnail inside main loop (for example “content.php”) but If it’s a working theme and you did not apply any major modifications that may cause the problem, you have to search for the solution outside of your theme files. For example check htaccess.
Thank you again Morteza!
This is a very barebone demo of the problem and I did not apply any modification to theme and the base plugins (gantry + rokcommon + roksprocket from RocketTheme) and there are no other plugins installed.
I’ve tried many installations and also with other theme and it’s a general problem in my hosting environment.
However on my xampp localhost it always works perfectly (I’ve tested with many installations).
I don’t know why/how on the domain server (Servage) the string “http://biro.name/wp-content/home43b/sub001/sc27622-OTFB/” is attached at the beginning of the links. Without this string the links are correct.
Just I don’t know how to stop this strings to be attached. I’ve tried removing them from the MySQL database with interconectit find and replace, but they get regenerated somehow.
I’ve set up a demo of the problem also here: http://andras.info
Problem solved! š
It was caused by a conflict of RokSprocket plugin with my specific hosting environment.
You can find the solution (commenting out 3 lines of php code) here.
The topic ‘Wrong featured image links’ is closed to new replies.