How to change value of variable in theme file with functions.php Wordpress?

by vanloc   Last Updated March 11, 2018 20:08 PM

I want to change values of the variable in my theme. I don't want to edit in this file because after update theme, it will be lost.

So, I want to update values of this variable in functions.php.

In post-simple.php file:

<p class="from_the_blog_excerpt small-font show-next">
    <?php
    $excerpt      = get_the_excerpt();
    echo string_limit_words( $excerpt, 15 );
    ?>
</p>

I want to change values 15(the length of string) to another value in the function string_limit_words($excerpt, $length).

In functions.php of child theme, I write this code look like:

function custom_excerpt_length( $excerpt, $length ) {
    $length = 30;
    return $length;
}
add_filter( 'flatsome_string_limit_words', 'custom_excerpt_length', 999 );

I tried to change values of $length to values 30 instead of 15 like default set on post-simple.php file.

But it does not a success. It still return $length = 15.



Related Questions


Custom wp_trim_words() function not trimming right

Updated March 21, 2016 08:03 AM

HTML in Divi Theme post excerpts

Updated March 30, 2017 18:08 PM


How to remove the space before the ellipsis in excerpt?

Updated September 03, 2016 08:05 AM

Custom excerpt legnths for specific pages

Updated February 12, 2017 14:03 PM