Help Fallback (thumbnail)

This should work global $post; $html = “”; $my_latest_posts_widget = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3 )); $html .= ‘<div id=”container_recent_posts_widget” class=”container_recent_posts_widget”>’; if( $my_latest_posts_widget->have_posts() ) : while( $my_latest_posts_widget->have_posts() ) : $my_latest_posts_widget->the_post(); $thumb = get_template_directory_uri() .’/assets/images/default-image-post-thumbnail-widget.jpg’; if ( has_post_thumbnail() ) { //override fallback image if post has any thumbnail $thumb = get_the_post_thumbnail_url(); } … Read more

Problem escaping text which contains html markups

To escape html content you can use wp_kses function. $allowed = array( ‘li’ => array(), ‘a’ => array( ‘href’ => true, ), ); echo wp_kses(‘<li><a href=”#” target=”_blank”>Category</a></li>’, $allowed); If you do not want to pass allowed array you can use default WordPress array for post content which is used in wp_kses_post function. echo wp_kses_post(‘<li><a href=”#” … Read more