strip_fragment_from_url

Strips the #fragment from a URL, if one is present.

Description

(string) strip_fragment_from_url( (string) $url ); 

Returns (string)

The altered URL.

Parameters (1)

0. $url (string)
The URL to strip.

Usage

  1. if ( !function_exists( 'strip_fragment_from_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/canonical.php'; 
  3.  
  4. // The URL to strip. 
  5. $url = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = strip_fragment_from_url($url); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/canonical.php  
  1. function strip_fragment_from_url( $url ) { 
  2. $parsed_url = @parse_url( $url ); 
  3. if ( ! empty( $parsed_url['host'] ) ) { 
  4. // This mirrors code in redirect_canonical(). It does not handle every case. 
  5. $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; 
  6. if ( ! empty( $parsed_url['port'] ) ) { 
  7. $url .= ':' . $parsed_url['port']; 
  8. $url .= $parsed_url['path']; 
  9. if ( ! empty( $parsed_url['query'] ) ) { 
  10. $url .= '?' . $parsed_url['query']; 
  11.  
  12. return $url;