With @Jacob Peattie suggestion, I have recoded it & it is working perfectly fine with functions.
/* Recent updated post & pages */
if ( ! function_exists( 'iq_recent_update' ) ) :
function iq_recent_update() {
$orig_post = $post;
global $post;
$args=array(
'posts_per_page' => 3,
'orderby' => 'modified',
'order' => 'DESC',
'post_type' => array('post', 'page'),
'post_status' => 'publish'
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<h3>Recent updates</h3>';
echo "<ul>";
while( $my_query->have_posts() ) {
$my_query->the_post();?>
<li><a href="https://wordpress.stackexchange.com/questions/334325/<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php
}
}
echo "</ul>";
$post = $orig_post;
wp_reset_query();
}
endif;