Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Fritser

    (@fritser)

    Never mind… forgot to add wp_reset_query() to my sidebar widget that gets the news…

    Thread Starter Fritser

    (@fritser)

    Ok, I have removed front-page.php and renamed it to page-home.php. Home still set as the static page but still the home page gets the_content() from the last news item.
    I really don’t understand what’s wrong here.

    Thread Starter Fritser

    (@fritser)

    Found a function that does what I need here.

    See code below:

    add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
    	/* limits image size to large setting */
    function replace_uploaded_image($image_data) {
    
        if (!isset($image_data['sizes']['large'])) return $image_data;
    
        // paths to the uploaded image and the large image
        $upload_dir = wp_upload_dir();
        $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
        $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];
    
        // delete the uploaded image
        unlink($uploaded_image_location);
    
        // rename the large image
        rename($large_image_location,$uploaded_image_location);
    
        // update image metadata and return them
        $image_data['width'] = $image_data['sizes']['large']['width'];
        $image_data['height'] = $image_data['sizes']['large']['height'];
        unset($image_data['sizes']['large']);
    
        return $image_data;
    }
    Thread Starter Fritser

    (@fritser)

    I changed both large large and medium sizes to 0, now 2 less images are being generated.

    What I realize now however is that WordPress saves a backup of the image. Which is definitely not necessary and the biggest problem because the site has used a lot of high quality pictures only as thumbnails.

    Thread Starter Fritser

    (@fritser)

    I solved it, kind of.

    <?php
    $string1 = "alignleft";
    $string2 = "alignright";
    $content = get_the_content();
    if(strstr($content,$string1) || strstr($content,$string2) )  {
    $content = str_replace('<p><img class="alignleft ', '<div class="photoleft"><span></span><img class="', $content);
    $content = str_replace('<p><img class="alignright ', '<div class="photoright"><span></span><img class="', $content);
    $content = str_replace('height="95" />', 'height="95" /></div><p>', $content);
    echo $content;
    }
    else {
    the_content('Read complete article');
    }
    ?>

    Also I was working on the code below, which doesn’t work because WordPress removes the empty span tags. Other than that it functions fine. The problem I had was that te size attribute defaults to medium.

    <?php
    function span_my_image_tag($html, $id , $class, $title, $size='thumbnail'){
    global $class;
    $class = $fubar;
    $html = str_replace('<img', '<div class="rounder"><span></span><img', $html);
    $html = str_replace('alt=""', 'alt="'.$title.'"', $html);
    $html = str_replace('height="95" />', 'height="95" /></div>', $html);
    return $html;
    }
    add_filter('get_image_tag','span_my_image_tag',10,5);
    ?>
    Thread Starter Fritser

    (@fritser)

    Does anyone know how to fix this? Or just a hint 🙂

Viewing 6 replies - 1 through 6 (of 6 total)