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">
    $excerpt      = get_the_excerpt();
    echo string_limit_words( $excerpt, 15 );

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.

Answers 1

Are you sure the flatsome_string_limit_words hook exists inside the string_limit_words function?

I think your best option is to override whole post-simple.php template in your child, but even this depends on how is built the parent theme.

Alex Sancho
Alex Sancho
March 11, 2018 20:21 PM

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

Strip div From Excerpt

Updated March 08, 2019 13:08 PM

How to remove the space before the ellipsis in excerpt?

Updated September 03, 2016 08:05 AM