Tag Info

Hot answers tagged

12

< and > are encoded as +ADw- and +AD4- in UTF-7. Now imagine the following: Someone sends +ADw-script+AD4-alert(+ACI-Hello+ACI-)+ADw-/script+AD4- as comment text. It will pass all validation unescaped. The database expects and treats all incoming data as UTF-8. Since all UTF-7 streams are valid UTF-8 too, this will never result in a SQL error, and ...


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( ...


2

i used this code in one of my last projects: function ng_get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = rtrim($excerpt,",.;:- _!$&#"); $excerpt = ...


2

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.


2

That conversion - among others - is caused by the wptexturize() filter being applied to the_content(). The sledge-hammer approach to preventing wp_texturize() being applied to the_content() is simply to remove the filter, like so: <?php remove_filter( 'the_content', 'wptexturize' ); ?>


1

It appears that the site is still using the Unicode character set from the page header, but the database may have been corrupted. Ask Linode for a backup restore and/or if they changed anything with their MySQL servers. If you don't run your own regular database backups, you should. Try WordPress › WP-DB-Backup « WordPress Plugins. You can also use ...


1

According to this page, you can use the tiny_mce_before_init filter, make sure the entity encoding is set to named, and then add whichever special characters you want to the entities array.


1

Quick and dirty, put this before your get_header() in your search.php <?php // Get the query string $query = get_search_query(); // if the first & last char is space, rip them $query = trim($query); // if there are more than one space, rip to one space $query = preg_replace('/\s\s+/', ' ',$query); // if chars count is less than 3, redirect them to ...


1

I know toscho doesn't like this very much, but anyway: Converted the input args to an array: function utf8_truncate( $args = array( 'string' => null, 'max_chars' => 200, 'append' => "\xC2\xA0…" ) ) { $args['string'] = strip_tags( $args['string'] ); $args['string'] = html_entity_decode( $args['string'], ENT_QUOTES, 'utf-8' ); // \xC2\xA0 ...


1

When one creates a WordPress site by default, or via the Fantastico tool in cPanel, it may create a blog with the Latin1 charset in the MySQL database. This causes Chinese characters (and other Unicode characters) to be switched into one or more ? question mark symbols, instead. The fix is to connect to your cPanel, connect to phpMyAdmin, find the WordPress ...


1

It's Wordpress. You could hack into wp-includes/formatting.php and comment out the contents of the sanitize_user() function. However, I don't think that's a good idea - it may compromize your site's security, and special characters can always cause trouble... And it's never a good idea to hack into the core (maybe you can do it also with remove_action() - ...


1

If you run a wp_kses() on the_excerpt() (through a filter) you can whitelist specific HTML tags and such. In your case, the code would probably look something like this: if( is_page( 'your_page' ) ) { add_filter( 'the_excerpt', 'wpse44363_filter_the_excerpt' ); } function wpse44363_filter_the_excerpt( $excerpt ) { // this allows no html, you can ...


1

You cannot change that value. The database schema is limited to 20 Bytes. See wp-admin/includes/schema.php: TABLE $wpdb->posts ( ID bigint(20) unsigned NOT NULL auto_increment, post_author bigint(20) unsigned NOT NULL default '0', post_date datetime NOT NULL default '0000-00-00 00:00:00', post_date_gmt datetime NOT NULL default '0000-00-00 ...


1

You have to either 1) take all the whitespace out of the script so WordPress does not add <p> tags and then the JS will work, or 2) disable autop in the post editor for all posts/pages (see http://codex.wordpress.org/Function_Reference/wpautop ) so WP doesn't add paragraph breaks, or 3) do the following, which leaves autop enabled globally, but lets ...


1

get_the_content() return what's in the editor, but wpautop filters and such are attached to the_content (which you don't need inside your split function - just apply it later manually with apply_filters( 'the_content', $output ); at the end. You should as well use strip_shortcodes( get_the_content() ); before splitting it up: $output = ...


1

so I really appreciate all the feedback and the answer that @kaiser and @t31os contributed. I am shaky with PHP so it was hard to put together a working block of code with kasier & t31os's answer. That's my fault for not being a very talented coder :-( But, I wanted to post the solution that I came up with by doing my own research on PHP.net and asking ...


1

Per a request from user2655393 I have written a version of his/her code that does not use output buffering, but uses string concatenation instead. $content = get_the_content(); $strings = wordwrap($content, 500, "<!--break-->"); //insert this every 500 chars, but preserve whole words. $chunks = explode("<!--break-->", $strings); create a new ...


1

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) ){ ...


1

Just do this with your string: $yourString = preg_replace ( '/å/' , 'a' , $yourString ) $yourString = preg_replace ( '/ä/' , 'a' , $yourString ) $yourString = preg_replace ( '/ö/' , 'o' , $yourString ) If you just want to do it with an SQL sentence, then you can try this : REPLACE(REPLACE(REPLACE(StringColumn, 'å', 'a') , 'ä', 'a') , 'ö', 'o') And you ...


1

Use the Multibyte String functions, in this case mb_strtoupper(). This is a general rule: in WordPress, output is usually encoded in UTF-8. Avoid single-byte functions like strlen(), substr() and others when there is a better mb_* function.


1

Use the function utf8_truncate() from this answer and fight your way through wp_trim_excerpt(). Sample code, not tested: add_filter( 'excerpt_more', 'wpse_69436_excerpt_more' ); function wpse_69436_excerpt_more( $more ) { add_filter( 'wp_trim_excerpt', 'wpse_69436_trim_excerpt' ); // we remove the more text here return ''; } function ...



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