Placeholder text in custom field

Hi,

I have the subscribe widget showing in the footer of the site.

1. I have added a new custom field "Name" and I would like to add placeholder text saying "Name" into this field.

Is there any way to do this?

(Please note: i have used css to hide the field titles.)

2. I would also like to change the placeholder wording in the main email field. I can try to use the branding plugin to do this unless there is a better solution you can recommend, that does not involve altering the core plugin files.

Many thanks
Chris

  • Luís

    Hi @chris,

    I hope had been good today!

    1) From what I know, you don't have an option to do that.

    One possibility is using Javascript to add a placeholder to the field.

    http://www.w3schools.com/jsref/prop_text_placeholder.asp

    Try this:

    document.getElementsByName('sbe_extra_field_name')[0].placeholder='new text for name';

    Use a plugin to add this custom Javascript code:

    https://wordpress.org/plugins/custom-javascript-editor/

    2) I affraid that you don't have any "better" choice to do that:

    2.1) Use Ultimate Branding plugin;

    2.2) Use a translation file (.mo) to change that line;

    2.3) Change the placeholder using Javascript;

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • chris

    Hi Luis,

    I have a custom functions.php file on the site.

    Could I add the javascript in there instead of using another plugin (the one you link to is 2 years out of date)?

    document.getElementsByName('sbe_extra_field_name')[0].placeholder='new text for name';

    I never work with java script in any complexity but I can probably work this out...through trial and error.

    The part i am not sure about is if i do add that to the function.php file how should it be wrapped.

    All the example I can find all call other javascript (.js) files

    I tried

    <script>
    function myFunction() {
        document.getElementsByName("sbe_extra_field_name")[0].placeholder='new text for name";
    }
    </script>

    But this results in a fatal error.

    Thanks for any help with this.

    Chris

  • Luís

    Hi @chris,

    I hope had been good today!

    You need to close the PHP tag before. Try the below code in your functions.php:

    function add_js_function(){
    ?>
    <script type="text/javascript">
        document.getElementsByName('sbe_extra_field_name')[0].placeholder='new text for name';
    </script>
    <?php
    }
    add_action('wp_footer','add_js_function');
    ?>

    Note: Don't forget, you need to close the PHP tag ( ?> ) before the script and open again after it ( <?php );

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.