Limit number of characters in different excerpts

Put the following code into functions.php: // TRUNCK STRING TO SHORT THE STRINGS function trunck_string($str = “”, $len = 150, $more=”true”) { if ($str == “”) return $str; if (is_array($str)) return $str; $str = strip_tags($str); $str = trim($str); // if it’s les than the size given, then return it if (strlen($str) <= $len) return $str; … Read more

Get users with different roles and call function on each of them (user_meta)

First, always var_dump() something if you aren’t sure what exactly you got. If you ain’t got XDebug installed and configured, just use printf( ‘<pre>%s</pre>’, htmlspecialchars( var_export( $dumpMe, true ) ) ); which will bring up an equally informative response. About the WP_User_Query) IIRC it returns objects which are instances of WP_User. You can test that … Read more

Custom Image Size in Insert Media

I ended up doing this: add_filter( ‘image_size_names_choose’, ‘jss_custom_image_sizes’ ); function jss_custom_image_sizes( $sizes ){ $custom_sizes = array( ‘customsize1’ => ‘Post Rectangle Image’, ‘customsize2’ => ‘Post Square Image’, ); return array_merge( $sizes, $custom_sizes ); }

Show Featured Image in else statement

The featured image-related functions do not offer any way to define a default/fallback image. So, you’ll have to define one yourself, e.g. <?php $featured_image = ( ” != get_the_post_thumbnail() ? get_the_post_thumbnail() : get_template_directory_uri() . ‘/images/img_not_available.png’ ); ?> <a href=”https://wordpress.stackexchange.com/questions/118789/<?php the_permalink(); ?>”><?php echo $featured_image; ?></a> Edit Three changes: More explicit conditional. get_the_post_thumbnail() returns an empty string … Read more

Disable trim in WordPress

Use the_content() instead. WordPress Codex Reference: the_content() the_excerpt() And till, if you want to enable the trim anywhere, wherever you want, manually try the Insert More Tag button in your Post editor:

get content from page through AJAX

Is this the correct way to do it ? This is not the correct way to do this. What you are doing, first, doesn’t make sense conceptually. When you load that page (assuming it loaded correctly) you would be loading the entire WordPress page, not just the comments. That is, you will load <html> all … Read more