Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Edit Image Widget WordPress

  • SOLVED

Currently, the Image Widget for wordpress give space for titles and description, but only the image links. I need to know how to edit the widget so that title, image, and description all link to the same place.

Here is the widget.php file:


<?php
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
if ( !empty( $image ) ) {
if ( $link ) {
echo '<a class="'.$this->widget_options['classname'].'-image-link" href="'.$link.'" target="'.$linktarget.'">';
}
if ( $imageurl ) {
echo "<img src=\"{$imageurl}\" style=\"";
if ( !empty( $width ) && is_numeric( $width ) ) {
echo "max-width: {$width}px;";
}
if ( !empty( $height ) && is_numeric( $height ) ) {
echo "max-height: {$height}px;";
}
echo "\"";
if ( !empty( $align ) && $align != 'none' ) {
echo " class=\"align{$align}\"";
}
if ( !empty( $alt ) ) {
echo " alt=\"{$alt}\"";
} else {
echo " alt=\"{$title}\"";
}
echo " />";
}

if ( $link ) { echo '</a>'; }
}
if ( !empty( $description ) ) {
$text = apply_filters( 'widget_text', $description );
echo '<div class="'.$this->widget_options['classname'].'-description" >';
echo wpautop( $text );
echo "</div>";
}
echo $after_widget;
?>


Thank you!

Answers (1)

2011-08-30

Hai Bui answers:

Here you go:
<?php

echo $before_widget;

if ( !empty( $title ) ) {
if ( $link ) {

echo '<a class="'.$this->widget_options['classname'].'-image-link" href="'.$link.'" target="'.$linktarget.'">';

}
echo $before_title . $title . $after_title;
if ( $link ) { echo '</a>'; }
}

if ( !empty( $image ) ) {

if ( $link ) {

echo '<a class="'.$this->widget_options['classname'].'-image-link" href="'.$link.'" target="'.$linktarget.'">';

}

if ( $imageurl ) {

echo "<img src=\"{$imageurl}\" style=\"";

if ( !empty( $width ) && is_numeric( $width ) ) {

echo "max-width: {$width}px;";

}

if ( !empty( $height ) && is_numeric( $height ) ) {

echo "max-height: {$height}px;";

}

echo "\"";

if ( !empty( $align ) && $align != 'none' ) {

echo " class=\"align{$align}\"";

}

if ( !empty( $alt ) ) {

echo " alt=\"{$alt}\"";

} else {

echo " alt=\"{$title}\"";

}

echo " />";

}



if ( $link ) { echo '</a>'; }

}

if ( !empty( $description ) ) {

$text = apply_filters( 'widget_text', $description );

echo '<div class="'.$this->widget_options['classname'].'-description" >';
if ( $link ) {

echo '<a class="'.$this->widget_options['classname'].'-image-link" href="'.$link.'" target="'.$linktarget.'">';

}
echo wpautop( $text );
if ( $link ) { echo '</a>'; }
echo "</div>";

}

echo $after_widget;

?>


Linda M comments:

Thanks you so much! Worked perfectly. Should have asked earlier rather than searching on my own for 2 hours this morning.


Hai Bui comments:

Cool... you are welcome. I'm glad I could help.