0

I am trying to get a function working with a conditional statement if that is possible. I can get the function working without the statement..I need it to determine whether or not the widget title is empty and if it is, to ignore the function, if it is not, it should use the function below. This function will insert an image as the title using the prefix title_(imagename).png

Thank you!

function html_widget_title( $title ) { $output = '<img src="/images/title_'.$title.'.png" alt="'.$title.'" title="'.$title.'"/>'; return $output; } add_filter( 'widget_title', 'html_widget_title' );

0

You can modify your filter function to add the condition:

function html_widget_title( $title ) {
    if ( '' != $title ) { 
        $output = '<img src="/images/title_'.$title.'.png" alt="'.$title.'" title="'.$title.'"/>';
        return $output;
    } else {
        return $title;
    }
}
add_filter( 'widget_title', 'html_widget_title' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.