I would like to change some code within a plugin with functions.php rather than changing code in the plugin.

This is the default:

echo '<div class="cta-box">';


            if (!empty( $instance['wsm-cta-image-url'] ) ) {
                echo '<img src="'. esc_attr( $instance['wsm-cta-image-url'] ) .'" alt="" />';
            }

                if (!empty( $instance['wsm-title'] ) ) {
                $title = wp_kses_post($instance['wsm-title']);
                    echo '<h4 class="cta-title">';
                    echo $title ;
                    echo '</h4>';
                }

                if (!empty( $instance['wsm-moretext'] ) ) {
                if (!empty( $instance['wsm-morelink'] ) ) :
                    echo '<span class="more-link"><a href="'. esc_attr( $instance['wsm-morelink'] ) . '"  target="'. esc_attr( $instance['wsm-target'] ) . '">'. esc_attr( $instance['wsm-moretext'] ) . '</a></span>';
                else:
                    echo '<span class="more-link"><a href="#"  target="'. esc_attr( $instance['wsm-target'] ) . '">'. esc_attr( $instance['wsm-moretext'] ) . '</a></span>';
                endif;

                }

            echo '</div><!--end .cta-box-->';

This is what I would like to do which is wrap the href link around the image:

            echo '<div class="cta-box">';


            if (!empty( $instance['wsm-cta-image-url'] ) ) {
                echo '<a href="'. esc_attr( $instance['wsm-morelink'] ) . '"  target="'. esc_attr( $instance['wsm-target'] ) . '"> <img src="'. esc_attr( $instance['wsm-cta-image-url'] ) .'" alt="" /></a>';
            }

                if (!empty( $instance['wsm-title'] ) ) {
                $title = wp_kses_post($instance['wsm-title']);
                    echo '<h4 class="cta-title">';
                    echo $title ;
                    echo '</h4>';
                }

                if (!empty( $instance['wsm-moretext'] ) ) {
                if (!empty( $instance['wsm-morelink'] ) ) :
                    echo '<span class="more-link"><a href="'. esc_attr( $instance['wsm-morelink'] ) . '"  target="'. esc_attr( $instance['wsm-target'] ) . '">'. esc_attr( $instance['wsm-moretext'] ) . '</a></span>';
                else:
                    echo '<span class="more-link"><a href="#"  target="'. esc_attr( $instance['wsm-target'] ) . '">'. esc_attr( $instance['wsm-moretext'] ) . '</a></span>';
                endif;

                }

            echo '</div>

Any ideas?

Read more here: Add filter to replace this code


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: