# Hướng dẫn ghi đè (override) folder INC trong child-theme Flatsome (ok)

{% embed url="<https://vuduchong.com/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome>" %}

<figure><img src="/files/WkuXE279SbtteZDdVQlV" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ikyCKuCaZ8RbHqREQnRN" alt=""><figcaption></figcaption></figure>

wp-content\themes\flatsome-child\functions.php

```php
<?php
function vdh_override_shortcodes()
{
  require get_stylesheet_directory() . '/inc/shortcodes/blog_posts.php';
}
add_action('wp_loaded', 'vdh_override_shortcodes', 10);
```

wp-content\themes\flatsome\inc\shortcodes\blog\_posts.php

```php
<?php
// [blog_posts]
function shortcode_latest_from_blog($atts, $content = null, $tag = '' ) {
	echo "aaaaaaaaaaaaa456";
	extract(shortcode_atts(array(
		"_id" => 'row-'.rand(),
		'style' => '',
		'class' => '',
		'visibility' => '',
		// Layout
		"columns" => '4',
		"columns__sm" => '1',
		"columns__md" => '',
		'col_spacing' => '',
		"type" => 'slider', // slider, row, masonery, grid
		'width' => '',
		'grid' => '1',
		'grid_height' => '600px',
		'grid_height__md' => '500px',
		'grid_height__sm' => '400px',
		'slider_nav_style' => 'reveal',
		'slider_nav_position' => '',
		'slider_nav_color' => '',
		'slider_bullets' => 'false',
	 	'slider_arrows' => 'true',
		'auto_slide' => 'false',
		'infinitive' => 'true',
		'depth' => '',
   		'depth_hover' => '',
		// posts
		'posts' => '8',
		'ids' => false, // Custom IDs
		'cat' => '',
		'category' => '', // Added for Flatsome v2 fallback
		'excerpt' => 'visible',
		'excerpt_length' => 15,
		'offset' => '',
		'orderby' => 'date',
		'order' => 'DESC',
		'tags' => '',
		// Read more
		'readmore' => '',
		'readmore_color' => '',
		'readmore_style' => 'outline',
		'readmore_size' => 'small',
		// div meta
		'post_icon' => 'true',
		'comments' => 'true',
		'show_date' => 'badge', // badge, text
		'badge_style' => '',
		'show_category' => 'false',
		//Title
		'title_size' => 'large',
		'title_style' => '',
		// Box styles
		'animate' => '',
		'text_pos' => 'bottom',
	  	'text_padding' => '',
	  	'text_bg' => '',
	  	'text_size' => '',
	 	'text_color' => '',
	 	'text_hover' => '',
	 	'text_align' => 'center',
	 	'image_size' => 'medium',
	 	'image_width' => '',
	 	'image_radius' => '',
	 	'image_height' => '56%',
	    'image_hover' => '',
	    'image_hover_alt' => '',
	    'image_overlay' => '',
	    'image_depth' => '',
	    'image_depth_hover' => '',
	), $atts));
	// Stop if visibility is hidden
  if($visibility == 'hidden') return;
	ob_start();
	$classes_box = array();
	$classes_image = array();
	$classes_text = array();
	// Fix overlay color
    if($style == 'text-overlay'){
      $image_hover = 'zoom';
    }
    $style = str_replace('text-', '', $style);
	// Fix grids
	if($type == 'grid'){
	  if(!$text_pos) $text_pos = 'center';
	  $columns = 0;
	  $current_grid = 0;
	  $grid = flatsome_get_grid($grid);
	  $grid_total = count($grid);
	  flatsome_get_grid_height($grid_height, $_id);
	}
	// Fix overlay
	if($style == 'overlay' && !$image_overlay) $image_overlay = 'rgba(0,0,0,.25)';
	// Set box style
	if($style) $classes_box[] = 'box-'.$style;
	if($style == 'overlay') $classes_box[] = 'dark';
	if($style == 'shade') $classes_box[] = 'dark';
	if($style == 'badge') $classes_box[] = 'hover-dark';
	if($text_pos) $classes_box[] = 'box-text-'.$text_pos;
	if($image_hover)  $classes_image[] = 'image-'.$image_hover;
	if($image_hover_alt)  $classes_image[] = 'image-'.$image_hover_alt;
	if($image_height) $classes_image[] = 'image-cover';
	// Text classes
	if($text_hover) $classes_text[] = 'show-on-hover hover-'.$text_hover;
	if($text_align) $classes_text[] = 'text-'.$text_align;
	if($text_size) $classes_text[] = 'is-'.$text_size;
	if($text_color == 'dark') $classes_text[] = 'dark';
	$css_args_img = array(
	  array( 'attribute' => 'border-radius', 'value' => $image_radius, 'unit' => '%' ),
	  array( 'attribute' => 'width', 'value' => $image_width, 'unit' => '%' ),
	);
	$css_image_height = array(
      array( 'attribute' => 'padding-top', 'value' => $image_height),
  	);
	$css_args = array(
      array( 'attribute' => 'background-color', 'value' => $text_bg ),
      array( 'attribute' => 'padding', 'value' => $text_padding ),
  	);
    // Add Animations
	if($animate) {$animate = 'data-animate="'.$animate.'"';}
	$classes_text = implode(' ', $classes_text);
	$classes_image = implode(' ', $classes_image);
	$classes_box = implode(' ', $classes_box);
	// Repeater styles
	$repeater['id'] = $_id;
	$repeater['tag'] = $tag;
	$repeater['type'] = $type;
	$repeater['class'] = $class;
	$repeater['visibility'] = $visibility;
	$repeater['style'] = $style;
	$repeater['slider_style'] = $slider_nav_style;
	$repeater['slider_nav_position'] = $slider_nav_position;
	$repeater['slider_nav_color'] = $slider_nav_color;
	$repeater['slider_bullets'] = $slider_bullets;
    $repeater['auto_slide'] = $auto_slide;
	$repeater['infinitive'] = $infinitive;
	$repeater['row_spacing'] = $col_spacing;
	$repeater['row_width'] = $width;
	$repeater['columns'] = $columns;
	$repeater['columns__md'] = $columns__md;
	$repeater['columns__sm'] = $columns__sm;
	$repeater['depth'] = $depth;
	$repeater['depth_hover'] = $depth_hover;
	$args = array(
		'post_status' => 'publish',
		'post_type' => 'post',
		'offset' => $offset,
		'cat' => $cat,
		'tag__in' => $tags ? array_filter( array_map( 'trim', explode( ',', $tags ) ) ) : '',
		'posts_per_page' => $posts,
		'ignore_sticky_posts' => true,
		'orderby'             => $orderby,
		'order'               => $order,
	);
	// Added for Flatsome v2 fallback
	if ( get_theme_mod('flatsome_fallback', 0) && $category ) {
		$args['category_name'] = $category;
	}
	// If custom ids
	if ( !empty( $ids ) ) {
		$ids = explode( ',', $ids );
		$ids = array_map( 'trim', $ids );
		$args = array(
			'post__in' => $ids,
            'post_type' => array(
                'post',
                'featured_item', // Include for its tag archive listing.
            ),
			'numberposts' => -1,
			'orderby' => 'post__in',
			'posts_per_page' => 9999,
			'ignore_sticky_posts' => true,
		);
		// Include for search archive listing.
		if ( is_search() ) {
			$args['post_type'][] = 'page';
		}
	}
$recentPosts = new WP_Query( $args );
// Get repeater HTML.
get_flatsome_repeater_start($repeater);
while ( $recentPosts->have_posts() ) : $recentPosts->the_post();
			$col_class    = array( 'post-item' );
			$show_excerpt = $excerpt;
			if(get_post_format() == 'video') $col_class[] = 'has-post-icon';
			if($type == 'grid'){
	        if($grid_total > $current_grid) $current_grid++;
	        $current = $current_grid-1;
	        $col_class[] = 'grid-col';
	        if($grid[$current]['height']) $col_class[] = 'grid-col-'.$grid[$current]['height'];
	        if($grid[$current]['span']) $col_class[] = 'large-'.$grid[$current]['span'];
	        if($grid[$current]['md']) $col_class[] = 'medium-'.$grid[$current]['md'];
	        // Set image size
	        if($grid[$current]['size']) $image_size = $grid[$current]['size'];
	        // Hide excerpt for small sizes
	        if($grid[$current]['size'] == 'thumbnail') $show_excerpt = 'false';
	    }
		?><div class="col <?php echo implode(' ', $col_class); ?>" <?php echo $animate;?>>
			<div class="col-inner">
			<a href="<?php the_permalink() ?>" class="plain">
				<div class="box <?php echo $classes_box; ?> box-blog-post has-hover">
          <?php if(has_post_thumbnail()) { ?>
  					<div class="box-image" <?php echo get_shortcode_inline_css($css_args_img); ?>>
  						<div class="<?php echo $classes_image; ?>" <?php echo get_shortcode_inline_css($css_image_height); ?>>
  							<?php the_post_thumbnail($image_size); ?>
  							<?php if($image_overlay){ ?><div class="overlay" style="background-color: <?php echo $image_overlay;?>"></div><?php } ?>
  							<?php if($style == 'shade'){ ?><div class="shade"></div><?php } ?>
  						</div>
  						<?php if($post_icon && get_post_format()) { ?>
  							<div class="absolute no-click x50 y50 md-x50 md-y50 lg-x50 lg-y50">
  				            	<div class="overlay-icon">
  				                    <i class="icon-play"></i>
  				                </div>
  				            </div>
  						<?php } ?>
  					</div>
          <?php } ?>
					<div class="box-text <?php echo $classes_text; ?>" <?php echo get_shortcode_inline_css($css_args); ?>>
					<div class="box-text-inner blog-post-inner">
					<?php do_action('flatsome_blog_post_before'); ?>
					<?php if($show_category !== 'false') { ?>
						<p class="cat-label <?php if($show_category == 'label') echo 'tag-label'; ?> is-xxsmall op-7 uppercase">
					<?php
						foreach((get_the_category()) as $cat) {
						echo $cat->cat_name . ' ';
					}
					?>
					</p>
					<?php } ?>
					<h5 class="post-title is-<?php echo $title_size; ?> <?php echo $title_style;?>"><?php the_title(); ?></h5>
					<?php if((!has_post_thumbnail() && $show_date !== 'false') || $show_date == 'text') {?><div class="post-meta is-small op-8"><?php echo get_the_date(); ?></div><?php } ?>
					<div class="is-divider"></div>
					<?php if($show_excerpt !== 'false') { ?>
					<p class="from_the_blog_excerpt <?php if($show_excerpt !== 'visible'){ echo 'show-on-hover hover-'.$show_excerpt; } ?>"><?php
					  $the_excerpt  = get_the_excerpt();
					  $excerpt_more = apply_filters( 'excerpt_more', ' [...]' );
					  echo flatsome_string_limit_words($the_excerpt, $excerpt_length) . $excerpt_more;
					?>
					</p>
					<?php } ?>
                    <?php if ( $comments == 'true' && comments_open() && '0' != get_comments_number() ) { ?>
                        <p class="from_the_blog_comments uppercase is-xsmall">
                            <?php
                                $comments_number = get_comments_number( get_the_ID() );
                            	/* translators: %s: comment count */
                                printf( _n( '%s Comment', '%s Comments', $comments_number, 'flatsome' ),
                                    number_format_i18n( $comments_number ) )
                            ?>
                        </p>
                    <?php } ?>
					<?php if($readmore) { ?>
						<button href="<?php echo get_the_permalink(); ?>" class="button <?php echo $readmore_color; ?> is-<?php echo $readmore_style; ?> is-<?php echo $readmore_size; ?> mb-0">
							<?php echo $readmore ;?>
						</button>
					<?php } ?>
					<?php do_action('flatsome_blog_post_after'); ?>
					</div>
					</div>
					<?php if(has_post_thumbnail() && ($show_date == 'badge' || $show_date == 'true')) {?>
					<?php if(!$badge_style) $badge_style = get_theme_mod('blog_badge_style', 'outline'); ?>
						<div class="badge absolute top post-date badge-<?php echo $badge_style; ?>">
							<div class="badge-inner">
								<span class="post-date-day"><?php echo get_the_time('d', get_the_ID()); ?></span><br>
								<span class="post-date-month is-xsmall"><?php echo get_the_time('M', get_the_ID()); ?></span>
							</div>
						</div>
					<?php } ?>
				</div>
				</a>
			</div>
		</div><?php endwhile;
wp_reset_query();
// Get repeater end.
get_flatsome_repeater_end($atts);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("blog_posts", "shortcode_latest_from_blog");

```

wp-content\themes\flatsome-child\inc\shortcodes\blog\_posts.php

```php
<?php
// [blog_posts]
function child_shortcode_latest_from_blog($atts, $content = null, $tag = '' ) {
  echo "aaaaaaaaaaaaa123";
	extract(shortcode_atts(array(
		"_id" => 'row-'.rand(),
		'style' => '',
		'class' => '',
		'visibility' => '',
		// Layout
		"columns" => '4',
		"columns__sm" => '1',
		"columns__md" => '',
		'col_spacing' => '',
		"type" => 'slider', // slider, row, masonery, grid
		'width' => '',
		'grid' => '1',
		'grid_height' => '600px',
		'grid_height__md' => '500px',
		'grid_height__sm' => '400px',
		'slider_nav_style' => 'reveal',
		'slider_nav_position' => '',
		'slider_nav_color' => '',
		'slider_bullets' => 'false',
	 	'slider_arrows' => 'true',
		'auto_slide' => 'false',
		'infinitive' => 'true',
		'depth' => '',
   		'depth_hover' => '',
		// posts
		'posts' => '8',
		'ids' => false, // Custom IDs
		'cat' => '',
		'category' => '', // Added for Flatsome v2 fallback
		'excerpt' => 'visible',
		'excerpt_length' => 15,
		'offset' => '',
		'orderby' => 'date',
		'order' => 'DESC',
		'tags' => '',
		// Read more
		'readmore' => '',
		'readmore_color' => '',
		'readmore_style' => 'outline',
		'readmore_size' => 'small',
		// div meta
		'post_icon' => 'true',
		'comments' => 'true',
		'show_date' => 'badge', // badge, text
		'badge_style' => '',
		'show_category' => 'false',
		//Title
		'title_size' => 'large',
		'title_style' => '',
		// Box styles
		'animate' => '',
		'text_pos' => 'bottom',
	  	'text_padding' => '',
	  	'text_bg' => '',
	  	'text_size' => '',
	 	'text_color' => '',
	 	'text_hover' => '',
	 	'text_align' => 'center',
	 	'image_size' => 'medium',
	 	'image_width' => '',
	 	'image_radius' => '',
	 	'image_height' => '56%',
	    'image_hover' => '',
	    'image_hover_alt' => '',
	    'image_overlay' => '',
	    'image_depth' => '',
	    'image_depth_hover' => '',
	), $atts));
	// Stop if visibility is hidden
  if($visibility == 'hidden') return;
	ob_start();
	$classes_box = array();
	$classes_image = array();
	$classes_text = array();
	// Fix overlay color
    if($style == 'text-overlay'){
      $image_hover = 'zoom';
    }
    $style = str_replace('text-', '', $style);
	// Fix grids
	if($type == 'grid'){
	  if(!$text_pos) $text_pos = 'center';
	  $columns = 0;
	  $current_grid = 0;
	  $grid = flatsome_get_grid($grid);
	  $grid_total = count($grid);
	  flatsome_get_grid_height($grid_height, $_id);
	}
	// Fix overlay
	if($style == 'overlay' && !$image_overlay) $image_overlay = 'rgba(0,0,0,.25)';
	// Set box style
	if($style) $classes_box[] = 'box-'.$style;
	if($style == 'overlay') $classes_box[] = 'dark';
	if($style == 'shade') $classes_box[] = 'dark';
	if($style == 'badge') $classes_box[] = 'hover-dark';
	if($text_pos) $classes_box[] = 'box-text-'.$text_pos;
	if($image_hover)  $classes_image[] = 'image-'.$image_hover;
	if($image_hover_alt)  $classes_image[] = 'image-'.$image_hover_alt;
	if($image_height) $classes_image[] = 'image-cover';
	// Text classes
	if($text_hover) $classes_text[] = 'show-on-hover hover-'.$text_hover;
	if($text_align) $classes_text[] = 'text-'.$text_align;
	if($text_size) $classes_text[] = 'is-'.$text_size;
	if($text_color == 'dark') $classes_text[] = 'dark';
	$css_args_img = array(
	  array( 'attribute' => 'border-radius', 'value' => $image_radius, 'unit' => '%' ),
	  array( 'attribute' => 'width', 'value' => $image_width, 'unit' => '%' ),
	);
	$css_image_height = array(
      array( 'attribute' => 'padding-top', 'value' => $image_height),
  	);
	$css_args = array(
      array( 'attribute' => 'background-color', 'value' => $text_bg ),
      array( 'attribute' => 'padding', 'value' => $text_padding ),
  	);
    // Add Animations
	if($animate) {$animate = 'data-animate="'.$animate.'"';}
	$classes_text = implode(' ', $classes_text);
	$classes_image = implode(' ', $classes_image);
	$classes_box = implode(' ', $classes_box);
	// Repeater styles
	$repeater['id'] = $_id;
	$repeater['tag'] = $tag;
	$repeater['type'] = $type;
	$repeater['class'] = $class;
	$repeater['visibility'] = $visibility;
	$repeater['style'] = $style;
	$repeater['slider_style'] = $slider_nav_style;
	$repeater['slider_nav_position'] = $slider_nav_position;
	$repeater['slider_nav_color'] = $slider_nav_color;
	$repeater['slider_bullets'] = $slider_bullets;
    $repeater['auto_slide'] = $auto_slide;
	$repeater['infinitive'] = $infinitive;
	$repeater['row_spacing'] = $col_spacing;
	$repeater['row_width'] = $width;
	$repeater['columns'] = $columns;
	$repeater['columns__md'] = $columns__md;
	$repeater['columns__sm'] = $columns__sm;
	$repeater['depth'] = $depth;
	$repeater['depth_hover'] = $depth_hover;
	$args = array(
		'post_status' => 'publish',
		'post_type' => 'post',
		'offset' => $offset,
		'cat' => $cat,
		'tag__in' => $tags ? array_filter( array_map( 'trim', explode( ',', $tags ) ) ) : '',
		'posts_per_page' => $posts,
		'ignore_sticky_posts' => true,
		'orderby'             => $orderby,
		'order'               => $order,
	);
	// Added for Flatsome v2 fallback
	if ( get_theme_mod('flatsome_fallback', 0) && $category ) {
		$args['category_name'] = $category;
	}
	// If custom ids
	if ( !empty( $ids ) ) {
		$ids = explode( ',', $ids );
		$ids = array_map( 'trim', $ids );
		$args = array(
			'post__in' => $ids,
            'post_type' => array(
                'post',
                'featured_item', // Include for its tag archive listing.
            ),
			'numberposts' => -1,
			'orderby' => 'post__in',
			'posts_per_page' => 9999,
			'ignore_sticky_posts' => true,
		);
		// Include for search archive listing.
		if ( is_search() ) {
			$args['post_type'][] = 'page';
		}
	}
$recentPosts = new WP_Query( $args );
// Get repeater HTML.
get_flatsome_repeater_start($repeater);
while ( $recentPosts->have_posts() ) : $recentPosts->the_post();
			$col_class    = array( 'post-item' );
			$show_excerpt = $excerpt;
			if(get_post_format() == 'video') $col_class[] = 'has-post-icon';
			if($type == 'grid'){
	        if($grid_total > $current_grid) $current_grid++;
	        $current = $current_grid-1;
	        $col_class[] = 'grid-col';
	        if($grid[$current]['height']) $col_class[] = 'grid-col-'.$grid[$current]['height'];
	        if($grid[$current]['span']) $col_class[] = 'large-'.$grid[$current]['span'];
	        if($grid[$current]['md']) $col_class[] = 'medium-'.$grid[$current]['md'];
	        // Set image size
	        if($grid[$current]['size']) $image_size = $grid[$current]['size'];
	        // Hide excerpt for small sizes
	        if($grid[$current]['size'] == 'thumbnail') $show_excerpt = 'false';
	    }
		?><div class="col <?php echo implode(' ', $col_class); ?>" <?php echo $animate;?>>
			<div class="col-inner">
			<a href="<?php the_permalink() ?>" class="plain">
				<div class="box <?php echo $classes_box; ?> box-blog-post has-hover">
          <?php if(has_post_thumbnail()) { ?>
  					<div class="box-image" <?php echo get_shortcode_inline_css($css_args_img); ?>>
  						<div class="<?php echo $classes_image; ?>" <?php echo get_shortcode_inline_css($css_image_height); ?>>
  							<?php the_post_thumbnail($image_size); ?>
  							<?php if($image_overlay){ ?><div class="overlay" style="background-color: <?php echo $image_overlay;?>"></div><?php } ?>
  							<?php if($style == 'shade'){ ?><div class="shade"></div><?php } ?>
  						</div>
  						<?php if($post_icon && get_post_format()) { ?>
  							<div class="absolute no-click x50 y50 md-x50 md-y50 lg-x50 lg-y50">
  				            	<div class="overlay-icon">
  				                    <i class="icon-play"></i>
  				                </div>
  				            </div>
  						<?php } ?>
  					</div>
          <?php } ?>
					<div class="box-text <?php echo $classes_text; ?>" <?php echo get_shortcode_inline_css($css_args); ?>>
					<div class="box-text-inner blog-post-inner">
					<?php do_action('flatsome_blog_post_before'); ?>
					<?php if($show_category !== 'false') { ?>
						<p class="cat-label <?php if($show_category == 'label') echo 'tag-label'; ?> is-xxsmall op-7 uppercase">
					<?php
						foreach((get_the_category()) as $cat) {
						echo $cat->cat_name . ' ';
					}
					?>
					</p>
					<?php } ?>
					<h5 class="post-title is-<?php echo $title_size; ?> <?php echo $title_style;?>"><?php the_title(); ?></h5>
					<?php if((!has_post_thumbnail() && $show_date !== 'false') || $show_date == 'text') {?><div class="post-meta is-small op-8"><?php echo get_the_date(); ?></div><?php } ?>
					<div class="is-divider"></div>
					<?php if($show_excerpt !== 'false') { ?>
					<p class="from_the_blog_excerpt <?php if($show_excerpt !== 'visible'){ echo 'show-on-hover hover-'.$show_excerpt; } ?>"><?php
					  $the_excerpt  = get_the_excerpt();
					  $excerpt_more = apply_filters( 'excerpt_more', ' [...]' );
					  echo flatsome_string_limit_words($the_excerpt, $excerpt_length) . $excerpt_more;
					?>
					</p>
					<?php } ?>
                    <?php if ( $comments == 'true' && comments_open() && '0' != get_comments_number() ) { ?>
                        <p class="from_the_blog_comments uppercase is-xsmall">
                            <?php
                                $comments_number = get_comments_number( get_the_ID() );
                            	/* translators: %s: comment count */
                                printf( _n( '%s Comment', '%s Comments', $comments_number, 'flatsome' ),
                                    number_format_i18n( $comments_number ) )
                            ?>
                        </p>
                    <?php } ?>
					<?php if($readmore) { ?>
						<button href="<?php echo get_the_permalink(); ?>" class="button <?php echo $readmore_color; ?> is-<?php echo $readmore_style; ?> is-<?php echo $readmore_size; ?> mb-0">
							<?php echo $readmore ;?>
						</button>
					<?php } ?>
					<?php do_action('flatsome_blog_post_after'); ?>
					</div>
					</div>
					<?php if(has_post_thumbnail() && ($show_date == 'badge' || $show_date == 'true')) {?>
					<?php if(!$badge_style) $badge_style = get_theme_mod('blog_badge_style', 'outline'); ?>
						<div class="badge absolute top post-date badge-<?php echo $badge_style; ?>">
							<div class="badge-inner">
								<span class="post-date-day"><?php echo get_the_time('d', get_the_ID()); ?></span><br>
								<span class="post-date-month is-xsmall"><?php echo get_the_time('M', get_the_ID()); ?></span>
							</div>
						</div>
					<?php } ?>
				</div>
				</a>
			</div>
		</div><?php endwhile;
wp_reset_query();
// Get repeater end.
get_flatsome_repeater_end($atts);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("blog_posts", "child_shortcode_latest_from_blog");

```

## Hướng dẫn ghi đè (override) folder INC trong child-theme Flatsome

🗣 Bài viết đăng bởi [Pinker](https://vuduchong.com/author/vuduchong) vào lúc 02-03-2023 và cập nhật lúc 17-12-2023 👁 3341 lượt xem\
Chia sẻ ➯\
&#x9;		if (navigator.share) {\
&#x9;		  // Enable the Web Share API button\
&#x9;		  const shareButton = document.getElementById('shareButton');\
&#x9;		  shareButton.addEventListener('click', () => {\
&#x9;			navigator.share({\
&#x9;			  title: 'Hướng dẫn ghi đè (override) folder INC trong child-theme Flatsome',\
&#x9;			  url: '<https://vuduchong.com/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome'\\>
&#x9;			})\
&#x9;			  .then(() => console.log('Shared successfully'))\
&#x9;			  .catch((error) => console.error('Sharing failed:', error));\
&#x9;		  });\
&#x9;		} else {\
&#x9;		  // If Web Share API is not supported, hide the button\
&#x9;		  const shareButton = document.getElementById('shareButton');\
&#x9;		  shareButton.style.display = 'none';\
&#x9;		}\
&#x9;[![Override Inc Flatsome](https://vuduchong.com/wp-content/uploads/2023/03/Override-INC-Flatsome.png)](https://vuduchong.com/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome)

Trong [WordPress](https://wordpress.org) nói chung và theme Flatsome nói riêng, có cơ chế tạo folder `child-theme` để chỉnh sửa được thuận tiện, không bị mất code khi update theme. Trong theme Flatsome chúng ta có thể ghi đè (override) được gần như toàn bộ các file, ngoại trừ chỉ có folder INC.

Để có thể ghi đè (override) inc trong theme Flatsome, các bạn áp dụng các bước sau, ở đây tôi sẽ ví dụ với file `/inc/ux_products.php`:

Bài viết khác

* [\[Woocommerce\] – Đổi vị trí giá sản phẩm xuống dưới mô tả ngắn](https://vuduchong.com/woocommerce-doi-vi-tri-gia-san-pham-xuong-duoi-mo-ta-ngan)
* [Fix lỗi không khởi động được MySQL trên Xampp – MySQL shutdown unexpectedly](https://vuduchong.com/loi-khong-khoi-dong-duoc-mysql)
* [Hiển thị địa chỉ thanh toán & thông tin giao hàng trong Thank You Page Woocommerce (khi không đăng nhập)](https://vuduchong.com/thong-tin-thanh-toan-woocommerce)
* [Hướng dẫn tự làm “Hệ thống chi nhánh Google Maps” cực kỳ đơn giản cho WordPress](https://vuduchong.com/he-thong-chi-nhanh-google-maps)
* [Mẫu thiết kế PSD theme MiuKid – Bài tập cắt HTML/CSS](https://vuduchong.com/mau-thiet-ke-psd-theme-miukid)

Nội dung bài viết

Toggle

* Bước 1. Sao chép file & folder
* Bước 2. Đổi tên function
* Bước 3. Đổi lại shortcode
* Bước 4. Khai báo ghi đè đường dẫn file

### Bước 1. Sao chép file & folder

Sao chép `/inc` từ theme Flatsome sang folder child-theme Flatsome (file nào cần thì sao chép, không thì copy tất cả cho nhanh)

### Bước 2. Đổi tên function

Mở file `/inc/shortcodes/ux_products.php` (hoặc file cần sửa trong child-theme) và đổi tên function

từ như này<br>

```
function ux_products($atts, $content = null, $tag) {}
```

sang như này<br>

```
function child_ux_products($atts, $content = null, $tag) {}
```

### Bước 3. Đổi lại shortcode

Kéo xuống cuối file và chỉnh sửa từ như này<br>

```
add_shortcode("ux_bestseller_products", "ux_products");
add_shortcode("ux_featured_products", "ux_products");
add_shortcode("ux_sale_products", "ux_products");
add_shortcode("ux_latest_products", "ux_products");
add_shortcode("ux_custom_products", "ux_products");
add_shortcode("product_lookbook", "ux_products");
add_shortcode("products_pinterest_style", "ux_products");
add_shortcode("ux_products", "ux_products");
```

sang như này

```
add_shortcode("ux_bestseller_products", "child_ux_products");
add_shortcode("ux_featured_products", "child_ux_products");
add_shortcode("ux_sale_products", "child_ux_products");
add_shortcode("ux_latest_products", "child_ux_products");
add_shortcode("ux_custom_products", "child_ux_products");
add_shortcode("product_lookbook", "child_ux_products");
add_shortcode("products_pinterest_style", "child_ux_products");
add_shortcode("ux_products", "child_ux_products");
```

### Bước 4. Khai báo ghi đè đường dẫn file

Mở `functions.php` trong child-theme và copy code sau

```
function vdh_override_shortcodes()
{
    require get_stylesheet_directory() . '/inc/shortcodes/ux_products.php';
    // Thêm file tương tự cần sửa vào đây
}
add_action('wp_loaded', 'vdh_override_shortcodes', 10);
```

Lưu ý rằng, khi theme cha được cập nhật, các thay đổi của trong `child-theme` sẽ không bị mất. Tuy nhiên, nếu các thay đổi trong theme cha liên quan đến các file trong thư mục /inc, bạn có thể cần phải cập nhật lại các file tương ứng trong `child-theme` của bạn để đảm bảo tính tương thích của theme và `child-theme`.

[![Hướng dẫn ghi đè (override) folder INC trong child-theme Flatsome](https://vuduchong.com/px.gif?utm_source=dmca_copy\&utm_medium=H%C6%B0%E1%BB%9Bng%20d%E1%BA%ABn%20ghi%20%C4%91%C3%A8%20\(override\)%20folder%20INC%20trong%20child-theme%20Flatsome\&utm_campaign=https://vuduchong.com/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome\&utm_content=C%C3%A1ch%20ghi%20%C4%91%C3%A8%20\(override\)%20folder%20INC%20trong%20theme%20Flatsome.%20Ch%E1%BB%89nh%20s%E1%BB%ADa%20t%C3%B9y%20th%C3%ADch%20kh%C3%B4ng%20lo%20m%E1%BA%A5t%20code%20khi%20update%20theme.%20H%C6%B0%E1%BB%9Bng%20d%E1%BA%ABn%20chi%20ti%E1%BA%BFt%20c%C3%A1c%20b%C6%B0%E1%BB%9Bc%20d%E1%BB%85%20l%C3%A0m.)](https://vuduchong.com/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome)[![This article is referenced content from https://vuduchong.com - Hướng dẫn ghi đè (override) folder INC trong child-theme Flatsome](https://vuduchong.com/px.gif?utm_source=dmca_copy\&utm_medium=H%C6%B0%E1%BB%9Bng%20d%E1%BA%ABn%20ghi%20%C4%91%C3%A8%20\(override\)%20folder%20INC%20trong%20child-theme%20Flatsome\&utm_campaign=https://vuduchong.com/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome\&utm_content=C%C3%A1ch%20ghi%20%C4%91%C3%A8%20\(override\)%20folder%20INC%20trong%20theme%20Flatsome.%20Ch%E1%BB%89nh%20s%E1%BB%ADa%20t%C3%B9y%20th%C3%ADch%20kh%C3%B4ng%20lo%20m%E1%BA%A5t%20code%20khi%20update%20theme.%20H%C6%B0%E1%BB%9Bng%20d%E1%BA%ABn%20chi%20ti%E1%BA%BFt%20c%C3%A1c%20b%C6%B0%E1%BB%9Bc%20d%E1%BB%85%20l%C3%A0m.)](https://vuduchong.com)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/advanced/huong-dan-ghi-de-override-folder-inc-trong-child-theme-flatsome-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
