before_last_bar()WP 2.8.0

Remove last item on a pipe-delimited string.

Meant for removing the last item in a string, such as 'Role name|User role'. The original string will be returned if no pipe '|' characters are found in the string.

No Hooks.


String. Either $string or everything before the last pipe.


before_last_bar( $string );
$string(string) (required)
A pipe-delimited string.


Since 2.8.0 Introduced.

Code of before_last_bar() WP 6.0

function before_last_bar( $string ) {
	$last_bar = strrpos( $string, '|' );
	if ( false === $last_bar ) {
		return $string;
	} else {
		return substr( $string, 0, $last_bar );