When using CF7 (Contact Form 7) is there any way to get the placeholder text from a php function?
I’ve tried using a shortcode to call the php function, but it doesn’t work.
Here is my test:
function.php code:
add_filter( 'wpcf7_form_elements', 'do_shortcode' );
add_shortcode( 'get_placeholder', 'get_placeholder_func' );
function get_placeholder_func () {
return "Hello world";
}
CF7 template:
[get_placeholder]
[text the-field placeholder [get_placeholder]]
First line works fine and outputs the text returned from the php function.
Second line doesn’t work as it only outputs a end-bracket.
I know I can do it by using js/jQuery, but it is a bit messy.
Can anybody help? Thanks 🙂
2
Answers
Why don’t you try the following:
Define the function
Then create your own input for CF7
Then, when editing CF7 you just have to call the input created
This shortcode will have
name-of-input
name and placeholder declared by the functionget_placeholder_func()
Hope it works.
I’m a little unclear as to why you would want to do this, but here’s a method.
Then your form tag would look like this: