Home › Forums › General Issues › Dynamic whatsapp number with fixed url and appended text
Hi! I’m trying for several months now to achieve a specific task.
I want to have a field in which I can input the whatsapp number, but to have the “https://wa.me/” and the append text “?text=exampletext” already fixed.
Hope that makes sense. The reason I need this is that I use a frontend from for user to create posts and input their contact info.
I tried the text field with prepend and append, but it’s not working.
Any guidance will be greatly appreciated!
I found a way to do it!
I made 3 shortcodes, one for the “https” part, one for the “whatsapp number” ACF field, and one for the final message.
It works great.
I leave the exact code in case someone needs it
// Prepend shortcode
function https_wa_shortcode() {
return 'https://wa.me/549';
}
add_shortcode('https_wa', 'https_wa_shortcode');
// Append shortcode
function hi_wa_shortcode() {
return '?text=Hi! ';
}
add_shortcode('hi_wa', 'hi_wa_shortcode');
// Post title shortcode
function post_title_shortcode(){
return get_the_title();
}
add_shortcode('post_title','post_title_shortcode');
// Append shortcode
function text_wa_shortcode() {
return ', here is the last part of the text.';
}
add_shortcode('text_wa', 'text_wa_shortcode');
I found this thread which seems to have solved it.
https://stackoverflow.com/questions/74909221/dinamically-create-a-link-using-acf-advanced-custom-field-custom-value/76353138#76353138
But I’m not sure how to implement it
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.