Home › Forums › Guestbook Add-On › Alternate ways to display additional fields (from the add-on) › Reply To: Alternate ways to display additional fields (from the add-on)
25 August 2021 at 14:36
#1509
Marcel Pol
Keymaster
Hi Aleksandr,
No problem about asking this. The 3 options for display are the most common ways for displaying. It can be changed and customized, but often that needs custom code for that specific desire/need.
What I did is disable the date fields and also the City/Origin field in the read-settings.
Then this next code can go to a custom plugin, or can be added to the functions.php of your theme.
You might want to check if the slugs of both fields are correct.
function gwolle_gb_author_name_html_add_meta_from_addon( $html, $entry ) {
if ( ! function_exists( 'gwolle_gb_addon_get_meta_for_preview' ) ) {
return $html;
}
$origin = $entry->get_author_origin();
if ( strlen(str_replace(' ', '', $origin)) > 0 ) {
$html .= '
<span class="gb-author-origin">
<span class="gb-author-origin-from-text"> ' . /* translators: city or origin */ esc_html__('from', 'gwolle-gb') . '</span>
<span class="gb-author-origin-text"> ' . gwolle_gb_sanitize_output($origin) . '</span>
</span>';
}
$cottage = gwolle_gb_addon_get_meta_for_preview( $entry->get_id(), 'cottage' );
if ( ! $cottage ) {
$cottage = gwolle_gb_addon_get_meta( $entry->get_id(), 'cottage' );
}
$year = gwolle_gb_addon_get_meta_for_preview( $entry->get_id(), 'year-visited' );
if ( ! $year ) {
$year = gwolle_gb_addon_get_meta( $entry->get_id(), 'year-visited' );
}
if ( strlen($cottage) > 0 ) {
$html .= '<span class="gb-author-cottage-text"> stayed in ' . $cottage . '</span>';
}
if ( strlen($year) > 0 ) {
$html .= '<span class="gb-author-cottage-text"> during ' . $year . ' wrote</span>';
}
var_dump($html);
return $html;
}
add_filter( 'gwolle_gb_author_name_html', 'gwolle_gb_author_name_html_add_meta_from_addon', 10, 2 );
Does it work for you?