Limit bio to 'X' number of charcters
-
Hi there
We want to display random number of authors on our sidebar with their photo, name and an excerpt of their bio. How can we limit the length of the bio shown?
Development site is at http://yazam.972creative.com/
Thanks!
Todd
-
Forgot to add – you can see a mock up of what we’re trying to achieve at http://bit.ly/1qXIiMo
Thanks again
ToddHi Todd
If you would to show a set number of authors but a random selection the plug-in and do that just select a random order and limit the number shown
If you wish to sown a random number of authors then you will need to call the plug-in code directly and change the number to shown in your code
example code is here
http://authoravatars.wordpress.com/documentation/developers-guide/Paul
Sorry Paul. I wasn’t clear.
Plugin gives me the output I need (5 authors, random). But if you see it displays full bio. I want to display only the first 55 characters for example, same way blog post excerpt works. How can I do this?
Thanks!
I see
I have added a new filter for you the git version
https://github.com/pbearne/wp-author-avatars
download from here https://github.com/pbearne/wp-author-avatars/archive/master.zip$biography = apply_filters( ‘aa_user_biography_filter’, $biography );
which you can hook into and truncate the bio’s as you need to
intructions can be found here http://codex.wordpress.org/Plugin_API
use wp_trim_words() http://codex.wordpress.org/Function_Reference/wp_trim_words
added a filter info is here
http://codex.wordpress.org/Function_Reference/add_filterI hope this helps
I’m vaguely familiar with hooking into the plugin with API.
Could you give me the code to add to my functions.php file?
I saw on your Github that someone else had the same feature request as I did. Have you thought about adding this to the widget options?
Really appreciated!
[ No bumping please. ]
add_fliter( 'aa_user_biography_filter', 'todds_user_biography_filter' ); function todds_user_biography_filter( $bio ){ return wp_trim_words( $bio, 20, '' ); }
I haven’t tested this
It needs the latest code from githubremove the ” in wp_trim_word to get … at end of text
Change the 20 if too longThe add_fileter line can be put into a init setup function if you have one
Good luck
paul
Hmm…
Add this to the end of our child theme’s functions.php file but didn’t seem to do anything.
Any ideas?
Hi Paul
Any further help you can give? It’d be really appreciated.
Thanks!
I needed to do the same thing – found a solution:
1) Open ‘UserList.class.php’ in the /lib/ directory in the plugin
2) Go to line 425 or there abouts
3) Replace this:
$biography = get_the_author_meta( 'description', $user->user_id );
with this:
//*** The following two lines to truncate bio $biography1 = get_the_author_meta( 'description', $user->user_id ); $biography = wp_trim_words( $biography1, 40, '...' ); //$biography = get_the_author_meta( 'description', $user->user_id );
4) Change the number ’40’ to the number of words you want and the ‘…’ to what you want to appear at the end of the truncation. Or you can leave those as is.
5) Save and overwrite
The downside is this change could be overwritten if the plugin was ever updated.
I will try to workout why the filter doesn’t work as this should do the same
I have coded this into the plug-in
you can test it by installing the master from github
https://github.com/pbearne/wp-author-avatars/archive/master.zip
This will included in the next release
Paul
Thanks guys.
Paul – this means just download your file from Github and install it. All the code updates are already there? Is there a settings page to control things?
Thanks!
yes that should work
the limit is in the advance part of the widget and under the photo in the short-code creator there is a filter that can be set as global filter more on that as i update the docs
the default is 100 words for now I am thinking of removing the default or setting very high
Paul
Thanks Paul. Forgot to update this on the client site.
Any way of adding a “Read More” text and link instead of the “…” at the end of the truncated text?
- The topic ‘Limit bio to 'X' number of charcters’ is closed to new replies.