Edit custom field placeholder

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Edit custom field placeholder

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 year, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #33562
    jason6666h96
    jason6666h96
    Participant

    Hi,

    Where can I edit the custom field placeholder in the plugin?

    I use text type.

    Thanks.

    Attachments:
    You must be logged in to view attached files.
    #33569
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Well, unfortunately there is no option for that, but you can try a custom code for that.

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_action('wp_footer', 'wp_footer_change_filter_input_placeholder', 9999);
    function wp_footer_change_filter_input_placeholder() {
    	?>
    	<script>
    	(function(){
    		let text = "My placeholder text";
    		setTimeout(function() {
    			document.querySelectorAll('fieldset.asp_custom_f input[type=text]').forEach(function(el){
    				el.placeholder = text;
    			})
    		}, 100);
    	}())
    	</script>
    	<?php
    }

    Change the text variable in the code for the input text you want.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #33599
    jason6666h96
    jason6666h96
    Participant

    Thanks for your help.

    If I have two text-type custom fields, the first one is “Name”, the second one is “Number”.
    Could you tell me how to do this?
    Thank you.

    #33606
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Might be possible:

    add_action('wp_footer', 'wp_footer_change_filter_input_placeholder', 9999);
    function wp_footer_change_filter_input_placeholder() {
    	?>
    	<script>
    	(function(){
    		let fields = {
    			"field-name1": "My placeholder text1",
    			"field-name2": "My placeholder text2"
    		};
    		setTimeout(function() {
    			Object.keys(fields).forEach(function(k){
    				let text = fields[k];
    				document.querySelectorAll('fieldset.asp_custom_f input[name*='+k+']').forEach(function(el){
    					el.placeholder = text;
    				});
    			});
    		}, 100);
    	}())
    	</script>
    	<?php
    }

    In the code change the fields variable -> on the left side are the custom field keys, on the right side the placeholder for that field.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.