Title: PHP urlencode() breaks filter function
Last modified: August 19, 2016

---

# PHP urlencode() breaks filter function

 *  Resolved [toneburst](https://wordpress.org/support/users/toneburst/)
 * (@toneburst)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/php-urlencode-breaks-filter-function/)
 * I’m trying to get the following code to work in my plugin:
 *     ```
       function ell_gmap_add_media_button( $context ) {
       	global $post;
       	$post_id = $post->ID;
       	//global $wpdb;
   
       	$ell_gmap_media_button = '%s' . '<a href="media-upload.php?';
   
       	// Get saved Geotag data from post if present
       	$field = 'ell_gmap_geotag_data';
       	$saved_geotag_data = get_post_meta($post_id, 'ell_gmap_geotag_data', true);
       	if( $saved_geotag_data ) {
       		$saved_values = explode( ',', $saved_geotag_data );
       		$lat          = str_replace( 'lat=', '', $saved_values[0] );
       		$lng          = str_replace( 'lng=', '', $saved_values[1] );
       		$title        = str_replace( 'title=', '', $saved_values[2] );
       		$title = urlencode( $title ); // <-- Breaks script
       		$description  = str_replace( 'description=', '', $saved_values[3] );
       		$ell_gmap_media_button .= "lat=$lat&lng=$lng&title=$title&description=$description&";
   
       	}
   
       	$ell_gmap_media_button_image = get_plugin_dir() . '/img/mediabutton.png';
       	$ell_gmap_media_button .= "post_id=$post_id&tab=ell_insert_gmap_tab&TB_iframe=true\" class=\"thickbox\" title=\"Geotag Post\"><img src=\"$ell_gmap_media_button_image\" /></a>";
   
       	return sprintf($context, $ell_gmap_media_button);
       }
       add_filter( 'media_buttons_context', 'ell_gmap_add_media_button' );
       ```
   
 * However, when I add the urlencode() function, this part of the script breaks (
   ie the extra Media Button isn’t added, and in fact, all the Media Buttons disappear.
   Removing the urlencode() function restores the intended functionality. The title
   and description vars from the post custom field may contain spaces and special
   characters, and since I need to pass them in the URL string, I’d like to make
   sure they’re properly URL-encoded.
 * What am I doing wrong?
 * a|x

Viewing 1 replies (of 1 total)

 *  Thread Starter [toneburst](https://wordpress.org/support/users/toneburst/)
 * (@toneburst)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/php-urlencode-breaks-filter-function/#post-1575316)
 * Fixed it! The string to be processed contained ‘ characters, which broke the 
   urlencode function.
 * a|x

Viewing 1 replies (of 1 total)

The topic ‘PHP urlencode() breaks filter function’ is closed to new replies.

## Tags

 * [urlencode](https://wordpress.org/support/topic-tag/urlencode/)

 * 1 reply
 * 1 participant
 * Last reply from: [toneburst](https://wordpress.org/support/users/toneburst/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/php-urlencode-breaks-filter-function/#post-1575316)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
