Skip Navigation

[Gelöst] remove Archive: from wpv-archive-title

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Provided custom filter hook to solve client's problem.

This support ticket is created vor 8 Jahre, 4 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 - -
- - - - - - -

Supporter timezone: Europe/Prague (GMT+01:00)

This topic contains 4 Antworten, has 4 Stimmen.

Last updated by Mohammed vor 6 Jahre, 2 Monate.

Assisted by: Jan.

Author
Artikel
#348557

Is there any way of removing Category:, Archive: etc from [wpv-archive-title] in all achieves and taxonomies.

I visited this URL https://toolset.com/forums/topic/page-title-of-wordpress-archive-revisited/ which didn't work

I'm using a child toolset bootstrap theme.

#348604

Jan
Supporter

Languages: Englisch (English )

Timezone: Europe/Prague (GMT+01:00)

Dear paulG-5,
those prefixes "Category:", "Archive:" and such come from WordPress core (they're hardcoded in the get_the_archive_title() function, see https://developer.wordpress.org/reference/functions/get_the_archive_title/).

There is only one way to get rid of them, and that is hooking into the get_the_archive_title filter, searching for the prefix in the title and removing it.

Try putting this code into your theme's functions.php file:

add_filter( 'get_the_archive_title', 'paulg_5_get_the_archive_title' );

function paulg_5_get_the_archive_title( $title ) {
	$prefixes_to_remove = array(
		'Year: ',
		'Archive: ',
		'Category: '
		// Add other prefixes you want to remove...
	);

	foreach( $prefixes_to_remove as $prefix ) {
		// If title starts with $prefix, remove it and finish
		if( $prefix == substr( $title, 0, strlen( $prefix ) ) )  {
			return substr( $title, strlen( $prefix ) );
		}
	}

	// No prefix was matched
	return $title;
}

However, if you plan to use it on a multilingual site, it gets even more complicated - please let me know if this is the case, and I'll provide a more robust solution.

#348606

Perfect. Thank you.

#606165

it's work great.

but how's coding for custom category for custom post type?

#606321

Hi Sarun,

I know that this is an old ticket.I'm asking if you still need assistance regarding this.

If so, please open a new ticket and mention this ticket URL there so that we can catch you request and work on it.

Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.