[Resolved] PHP error function 'lh_remove_categories'

Home Forums Support [Resolved] PHP error function 'lh_remove_categories'

Home Forums Support PHP error function 'lh_remove_categories'

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #701525
    andrew

    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

    #701582
    Leo
    Staff
    Customer Support

    Hi there,

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

    I’ve edited your code above.

    #701607
    andrew

    Thank you very much
    Now everything is OK ๐Ÿ™‚

    #701609
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.