Archived topic
I need help with custom code I made
1 reply · Started by eduard sans on March 18, 2021
Hi guys! ok, so here's my case. I'm using this code in order to show a mandatory checkbox for "I agree to privacy policy" and to show a summary of certain data treatment (my lawyer said it should be there due to GDPR) that's displayed right under the comment box for when a user wants to join the conversation.
add_filter( 'comment_form_default_fields', 'tu_comment_form_change_cookies_consent' );
function tu_comment_form_change_cookies_consent( $fields ) {
$commenter = wp_get_current_commenter();
$consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
'<label for="wp-comment-cookies-consent">Acepto la <a target="_blank" href="https://mesquefisio.com/politica-de-privacidad/">política de privacidad.</a></label></p>
<details class="proteccion-datos"><summary>Haz click aquí si quieres leer más información sobre Protección de Datos</summary>
<strong>Responsable:</strong> Inmaculada González Aguilera <br/>
<strong>Finalidad:</strong> Moderar y responder comentarios de usuarios.<br/>
</details><br/>';
return $fields;
}
Everything works like a charm but here's the issue: now I'm doing a multilanguage site and I need this text to be displayed in another language as well. I thought of two possible solutions:
1) Add a conditional in php (I don't know how) to target the language of the page and display one message or another.
2) Convert this whole code in an Element so I can then easily translate it with WPML (I would prefer this option). The problem is that I couldn't find a hook that would work to display it exactly where I want it. Any ideas? Thanks!!
Hi there,
Unfortunately we aren't able to provide support for your own custom code in the support forum here as it's not related to GP or GPP at all:
https://generatepress.com/what-support-includes/
Filters cannot be added using the element module so you will have to go with option 1.
I would recommend checking with WPML's support team and see if they can provide you with the conditional tag.