1

I am trying to echo setting

    $this->settings['numberofwordsexcerpt'] = array(
        'title'   => __( 'Number of Words' ),
        'desc'    => __( 'Please enter here the number of words you want the latest posts on index to have.' ),
        'std'     => '25',
        'type'    => 'text',
        'section' => 'general'
    );

into this function in variable $word_limit

add_action('the_excerpt','limit_the_content'); 
function limit_the_content($content){
 $word_limit = $this->settings['numberofwordsexcerpt']; // HERE I AM TRYING to echo it

BUT doesn't work, I get the error

Fatal error: Using $this when not in object context
     $words = explode(' ', $content); return implode(' ', array_slice($words, 0, $word_limit)); }

I also tried with

$word_limit = $settings['numberofwordsexcerpt'];

And i get an error related to the fact that the variable $settings is not defined... Also tried

$word_limit = ?> <?php echo $settings['numberofwordsexcerpt']; ?> 

and get an error related to ";", tried deleting that and still error remains. Please help.

1 Answer 1

3
    $settings = get_option('mytheme_options'); 

    $word_limit  = $settings['numberofwordsexcerpt']; 

echo $word_limit;
Sign up to request clarification or add additional context in comments.

2 Comments

Yep, i also needed to do $settings = get_option('mytheme_options');
Yes it did, could not mark it because of the time. Thank you again for your help it's much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.