Site logo

Archived topic

PHP error function 'lh_remove_categories'

3 replies · Started by andrew on October 15, 2018

Viewing posts 1–4 of 4

Hi,
I want to display the category meta above the title of an article (both home and single page), so I used that code in function.php child theme:

add_filter( 'generate_category_list_output','lh_remove_categories' );
function lh_remove_categories( $categories ) {
	if ( is_single() ) {
		return '';
	}
  if ( is_home() ) {
		return '';
	}
	
	return $categories;
}

add_action( 'generate_before_entry_title','lh_single_cats_above_title' );
function lh_single_cats_above_title() {
	if ( is_single() ) {
		$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
		if ( $categories_list ) {
			printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
				_x( 'Categories', 'Used before category names.', 'generatepress' ),
				$categories_list
			);
		}
	}
  if ( is_home() ) {
		$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
		if ( $categories_list ) {
			printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
				_x( 'Categories', 'Used before category names.', 'generatepress' ),
				$categories_list
			);
		}
	}
}

The problem is this error in my error_log.php:
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'lh_remove_categories' not found or invalid function name in /home/****/public_html/wp-includes/class-wp-hook.php on line 286

How can I fix it?

Thanks

Hi there,

The filter name and function name needs to match (1st and 2nd line).

I've edited your code above.

Thank you very much
Now everything is OK :-)

No problem :)

This archived topic is closed to new replies.