Open antoinelbch opened 5 years ago
[list_categories]
The function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode.
Please see: https://github.com/WordPress/gutenberg/issues/3576
Change 'echo' in the code to 'return':
/** * Add Display Job Categories Shortcode: [list_categories] * * https://wpjobmanager.com/customization-snippets/#displayCat */ public function dm_display_wpjm_categories () { $terms = get_terms( array( 'taxonomy' => 'job_listing_category', 'hide_empty' => false, ) ); $output = ''; if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ // echo '<ul>'; $output .= '<ul>'; foreach ( $terms as $term ) { // echo '<li>' . '<a href="' . esc_url( get_term_link( $term ) ) . '">' . $term->name . '</a></li>'; $output .= '<li>' . '<a href="' . esc_url( get_term_link( $term ) ) . '">' . $term->name . '</a></li>'; } // echo '</ul>'; $output .= '</ul>'; } return $output; }
Yes this is correct, from this snippet: https://gist.github.com/davoraltman/98920d5d06aa717cfce2f9559108cb52#file-functions-php
Steps to Reproduce
[list_categories]
Reason
The function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode.
Solution
Please see: https://github.com/WordPress/gutenberg/issues/3576
Change 'echo' in the code to 'return':