woocommerce offtopic - short description in shop page after title

admin2025-01-07  5

hello i'm using this code in my functions.php file to display a short description in shop page (woocommerce page) but the discription goes before the title can some one help me please to display it after the title thank you

  $excerpt = explode(' ', get_the_excerpt(), $limit);
  if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt).'...';
  } else {
    $excerpt = implode(" ",$excerpt);
  } 
  $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
  return $excerpt;
}


function woocommerce_after_shop_loop_item_title_short_description() {
    if ( has_excerpt() ) :
        ?>
        <div itemprop="description">
            <?php echo apply_filters( 'woocommerce_short_description', excerpt(10) ) ?>
        </div>
        <?php
    endif;
}
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_after_shop_loop_item_title_short_description', 5 );```

hello i'm using this code in my functions.php file to display a short description in shop page (woocommerce page) but the discription goes before the title can some one help me please to display it after the title thank you

  $excerpt = explode(' ', get_the_excerpt(), $limit);
  if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt).'...';
  } else {
    $excerpt = implode(" ",$excerpt);
  } 
  $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
  return $excerpt;
}


function woocommerce_after_shop_loop_item_title_short_description() {
    if ( has_excerpt() ) :
        ?>
        <div itemprop="description">
            <?php echo apply_filters( 'woocommerce_short_description', excerpt(10) ) ?>
        </div>
        <?php
    endif;
}
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_after_shop_loop_item_title_short_description', 5 );```
Share Improve this question edited Jun 10, 2020 at 20:47 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 10, 2020 at 11:20 maryamarya 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

An Link to your page might be useful to see exactly what is happening.

To display something After the Title and before the shop loop I would suggest Hooking in to the 'woocommerce_before_shop_loop' Hook

by doing something like:

add_action( 'woocommerce_before_shop_loop', 'woocommerce_after_shop_loop_item_title_short_description', 10 );

function woocommerce_after_shop_loop_item_title_short_description() {
echo '';
echo 'something here';
echo '';
}

Screenshot of my example in action:

Checkout this Visual Hook Guide for some more information on where the different hooks are https://businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736251897a2.html

最新回复(0)