0
<a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>

The above is the code snippet from one of the widgets of my theme.

Now in the widget arrangement, this is the situation →

$instance['number_of_words']     = absint( $new_instance['number_of_words'] );

the above setting is to handle how many numbers of words do we wish to show in the title?

how should we pass this variable $instance['number_of_words']

<?php the_title(); ?>
  • how is a call the snippet in the widget ? with a action or the widget instanciation ? – mmm Oct 19 '17 at 10:43
1

You can't pass this variable to the_title() but you can simply wrap it in wp_trim_words function.

echo wp_trim_words( get_the_title(), $number_of_words );

| improve this answer | |
  • thank you so much it worked. I have accepted your answer. – The WP Intermediate Oct 19 '17 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.