How to change the display format of an attribute

I have an attribute called “Services” of type checkboxes. The output of multiple services selected is each service followed by a comma. How do I change the output so that each service is listed on a separate line instead of a comma?

I figured it out after a wasted conversation with chatgpt. In case anyone else has the same problem, here is what I did to get the desired result:

First of all, the rendering of the attributes is located in the plugin, not in the theme directory.
The file I modified is located here:
hivepress/includes/fields/class-select.php

The function that I changed is located at line 224.
The name of the function is public function get_display_value()
Essentially what I did was I modified the coding by inserting the < br > tag in the appropriate places to create new lines both after the label and for each attribute value:
Here is the modified function:

public function get_display_value() {
		if ( ! is_null( $this->value ) ) {
			$labels = [];

			foreach ( (array) $this->value as $value ) {
				$label = hp\get_array_value( $this->options, $value );

				if ( is_array( $label ) ) {
					$label = hp\get_array_value( $label, 'label' );
				
				}

				if ( strlen( $label ) ) {
					$labels[] = $label;
				}
			}

			if ( $labels ) {
			    $returnvalue = '<br>' . implode( '<br>', $labels );
			     return $returnvalue;
			}
		}
	}

Hi,

Thank you for your solution; maybe it will be useful for someone. Please note that if you changed the code in the theme’s core files without using a Code Snippet plugin or child theme, then if we release an update, all this data will be restored to the previous one.

By all means, if there is a more elegant way to do it using a code snippet, I am definitely interested.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.