|
1 | 1 | <?php |
2 | 2 | /* |
3 | | -Plugin Name:orWidget |
| 3 | +Plugin Name:OpenElementorWidget |
4 | 4 | Description: Custom widget for Elementor |
5 | 5 | Version: 1.0 |
6 | 6 | Author: Davide |
7 | 7 | */ |
8 | 8 |
|
9 | 9 | // Register the custom widgets with Elementor |
10 | | -add_filter('get_the_excerpt', function ($excerpt) { |
11 | | - |
12 | | - $excerpt_length = 40; // Change excerpt length |
13 | | - |
14 | | - global $post; |
15 | | - |
16 | | - if ( |
17 | | - is_archive() || is_search() |
18 | | - ) { |
19 | | - $post = get_post(); |
20 | | - } |
21 | | - |
22 | | - if ( |
23 | | - has_excerpt($post) |
24 | | - ) { |
25 | | - } else { |
26 | | - $content = get_the_content(); |
27 | | - $first_word = substr($content, 0, strpos($content, ' ')); |
28 | | - $content = substr($content, strpos($content, ' ') + 2); |
29 | | - $excerpt = wp_trim_words($content, $excerpt_length); |
30 | | - $excerpt = $first_word . ' ' . $excerpt; |
31 | | - } |
32 | | - |
33 | | - return $excerpt; |
| 10 | +add_filter('the_excerpt', function ($excerpt) { |
| 11 | + |
| 12 | + $excerpt_length = 40; // Change excerpt length |
| 13 | + |
| 14 | + global $post; |
| 15 | + |
| 16 | + if ( |
| 17 | + is_archive() || is_search() |
| 18 | + ) { |
| 19 | + $post = get_post(); |
| 20 | + } |
| 21 | + |
| 22 | + if (has_excerpt($post)) { |
| 23 | + echo "porva"; |
| 24 | + } |
| 25 | + else { |
| 26 | + $content = get_the_content(); |
| 27 | + $first_word = substr($content, 0, strpos($content, ' ')); |
| 28 | + $content = substr($content, strpos($content, ' ') + 2); |
| 29 | + echo $first_word; |
| 30 | + $excerpt = wp_trim_words($content, $excerpt_length); |
| 31 | + $excerpt = $first_word . ' ' . $excerpt; |
| 32 | + } |
| 33 | + |
| 34 | + return $excerpt; |
34 | 35 | }, 10, 2); |
35 | 36 | add_action('elementor/widgets/widgets_registered', 'register_OpenElementorWidget_widgets'); |
36 | 37 |
|
|
0 commit comments