before_last_bar() WordPress Function

The before_last_bar() function is used to return the content of a post before the last bar. This is useful for displaying a post teaser on a blog homepage.

before_last_bar( string $string ) #

Remove last item on a pipe-delimited string.


Description

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.


Top ↑

Parameters

$string

(string)(Required)A pipe-delimited string.


Top ↑

Return

(string) Either $string or everything before the last pipe.


Top ↑

Source

File: wp-includes/l10n.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.