Hot answers tagged

18

The codex is your friend and should be your first stop :-) The [...] is added by the_excerpt(). There is a filter supplied called the excerpt_more filter that is specifically included to customize the read more text after the excerpt To remove the [...] after the excerpt text, you can do the following function new_excerpt_more( $more ) { return ''; } ...


9

You can filter 'wpmu_validate_user_signup' and check if the error code matches the 4 character warning. Then just unset the error code. Sample plugin: <?php # -*- coding: utf-8 -*- /* Plugin Name: Allow short user names for multi site. */ add_filter( 'wpmu_validate_user_signup', 'wpse_59760_short_user_names' ); /** * Allow very short user names. * *...


9

There are some restrictions (caused by lengths of some columns in database). Taxonomies Taxonomy name - 32 characters Term name (and term slug) - 200 characters Posts Post type name - 20 characters Post name (slug) - 200 characters Meta key - 255 characters Options Option name - 64 characters Comments Commenter email - 100 characters Commenter url - ...


8

You're looking in the wrong place. When a user first attempts to register, their username and email is processed and sanitized inside the register_new_user() function in wp-login.php. This is where you want to do your filtering. Before the user is created, WordPress will pass the sanitized user login, email address, and an array or errors through the '...


6

That number is taken from wp_max_upload_size(), and there is a filter: 'upload_size_limit'. See wp-admin/includes/template.php. So this should work (not tested): add_filter( 'upload_size_limit', 'wpse_70754_change_upload_size' ); function wpse_70754_change_upload_size() { return 1000 * 1024; }


6

I think the answer is in the source. $username = wp_strip_all_tags( $username ); $username = remove_accents( $username ); // Kill octets $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities // If strict, reduce to ASCII for max portability. if ( $strict ) $...


5

To display 5 posts, say, use posts_per_page. See the Codex. $the_query = new WP_Query( array( 'brand' => 'sony-vaio','posts_per_page'=>5 ) );


5

As @StephenHarris pointed out there's also the pre_get_posts filter. function hwl_home_pagesize( $query ) { if ( is_category( 9 ) ) { // If you want "posts per page" $query->query_vars['posts_per_page'] = 1; return; } if ( is_category( 'movie' ) ) { // If you want "showposts" $query->...


5

I'm not really sure which is the real problem with code you posted, however I cant understand why use 2 functions when one is enough... add_filter( 'wp_handle_upload_prefilter', 'limit_uploads_for_user_roles' ); function limit_uploads_for_user_roles( $file ) { $user = wp_get_current_user(); // add the role you want to limit in the array $limit_roles =...


4

You can use the pre_get_posts hook (conditionals are available): function wpse47875_change_posts_per_page( $query ) { //Only alter main query. This only works for 3.3+ if( ! $query->is_main_query() ) return; if ( is_category('9') ){ //Display 4 posts for category 1 $query->set( 'posts_per_page', 4); } } ...


4

I took the example code from the Wordpress user_has_cap filter codex page and modified it. Add this code to your theme functions.php: function restrict_editing_old_posts( $allcaps, $cap, $args ) { // Bail out if we're not asking to edit or delete a post ... if( ( 'edit_post' != $args[0] && 'delete_post' != $args[0] ) // ... or user is admin ||...


4

As you can see in the WordPress Option Reference, there's an option called users_can_register. You can - per default - set it in your (network-)sites settings. 1 => Yes 0 => No As usual: There's a filter to intercept that from a plugin. "option_{$option_name}" So you can simply attach a callback to this filter and check the amount of users with a ...


4

Using the regex posted by Moaz (and adding capitals), we will need to hook into the registration_errors filter: // Restrict username registration to alphanumerics add_filter('registration_errors', 'limit_username_alphanumerics', 10, 3); function limit_username_alphanumerics ($errors, $name) { if ( ! preg_match('/^[A-Za-z0-9]{3,16}$/', $name) ){ $...


4

Build an array of categories: foreach ($categories as $category) { $cat[] = $category->cat_ID; } Then pass that to the query: $args=array( 'category__in' => $cat, 'order' =>DESC, 'post__not_in' => array($post->ID), 'posts_per_page'=>2, ); In other words, put the query after the foreach, not inside of it.


4

It were the sticky posts who ignored my posts_per_page. After setting 'ignore_sticky_posts' => true the result was correct !


3

the_content echoes post content. It does not return a string that you can manipulate. You need get_the_content() Swap those functions and it should work.


3

To get a specific length you can use: wp_trim_words function. It has 3 parameters. Text to trim. Ex: get_the_content() Number of words. Ex: 295 What to append after end of the text. Ex: '' This means null. Use this: <span> <?php echo wp_trim_words( get_the_content(), 295, '' ); ?> <i><a style="color:#1975D1;float:Right;" class=...


3

You can grab the first one or two paragraphs with a regular expression (regexp) function custom_excerpt( $content = '' ){ if( empty( $content ) ) return $content; $result = ''; $matches = array(); // grab all paragraphs from $content preg_match_all( '#<\s*p[^>]*>(.*?)<\s*/\s*p>#ui', $content, $matches ); if(...


3

first add this function to your functions.php file function max_title_length($title){ $max = 20; return substr( $title, 0, $max ). " &hellip;"; } then before the loop of the code you linked add this line to hook the above function: add_filter( 'the_title', 'max_title_length'); and after the loop remove this filter: remove_filter( 'the_title'...


3

This seem to work. Put in your functions.php: add_filter('pre_get_posts', 'limit_pages'); function limit_pages($query) { $query->max_num_pages = 5; if ($query->query_vars['paged'] > 5) { $query->query_vars['paged'] = 5; $query->query['paged'] = 5; } return $query; } But I guess you would still need some ...


3

As there can be more than one error for user names, the accepted answer could remove errors we would want to preserve. For example entering a user name of 123 would now pass whereas it should presumably still give the error message 'Sorry, usernames must have letters too!' Modified sample code to fix this: /* Plugin Name: Allow short user names for multi ...


3

In the form you have posted this is more of PHP question - you could use strlen() functions to determine length of original title and apply ellipsis conditionally. However in WP context you should consider using wp_trim_words() since trimming based on words looks tidier and it will take care of appending string of your choice whet cutting.


3

Piggybacking off Kaiser's answer: add_filter( 'option_users_can_register', 'limit_total_users' ); function limit_total_users( $option ) { // Registration turned off manually. Nothing to do here. if ( 0 === $option ) return $option; $user_count = count_users(); // Abort if we're above the limit if ( $user_count['total_users'] &...


3

First, please make sure you understand the difference between the_excerpt and the_content. You are asking about the_excerpt but I suspect that you might actually mean the_content. That said... You can filter the the_excerpt function with a filter of the same name. add_filter( 'the_excerpt', function ($excerpt) { return substr($excerpt,0,strpos($...


3

You can use WP_Query instead of get_posts and then you can use the properties which are set for you: $post_count - The number of posts being displayed. $found_posts -The total number of posts found matching the current query parameters $max_num_pages - The total number of pages. Is the result of $found_posts / $posts_per_page


3

As others have already pointed out, using the excerpt_more filter hook is the right way to go. Just wanted to add that you don't have to write a function that returns an empty string. WordPress has a few built in functions to return true, false, zero, null, empty string or empty array. In this case we need __return_empty_string() You can add this code to ...


3

You can use posts_per_page or numberposts. http://codex.wordpress.org/Template_Tags/get_posts#Parameters EDIT: Regarding your edit. You cannot have the posts_per_page different to the LIMIT in the SQL query. get_posts() creates an instance of WP_Query and returns it using the posts_per_page as the LIMIT.


3

You can approach this by first using a database query to count the number of pages that are already using the template: $query = "SELECT COUNT(*) as total FROM prefix_posts as p JOIN prefix_postmeta as m ON p.ID = m.post_id WHERE p.'post_type' = 'page' AND p.'post_status' = 'publish' AND m.'meta_key' = '_wp_page_template' AND m.'...


3

pre_get_posts alters all queries, back end and front end regardless. There are two very important checks that a large amount of people misses, that is the !is_admin() check which only targets the front end, and then the most important check, is_main_query() which will only alter the main query and not custom queries. You statement should look something ...


2

You can use my plugin Posts Creation Limits which has a per user, per role, per post type, per post status limiting system and combined with its post_creation_limits_custom_checks action hook and check if the user has created a post that day already - if so: show the the "limit reached message". For example: add_action( 'post_creation_limits_custom_checks', ...


Only top voted, non community-wiki answers of a minimum length are eligible