this code works correctly. But how to display

<?php echo $quote; ?>

on single.php?

It only appears inside the user profile page.

Do I need to display In single.php

function wpse_230369_quote_of_the_day( $user ) { 
$quote = esc_attr( get_option( 'quote_of_the_day' ) );

 <div class="visible-only-for-admin">
<h3>Quote of the Day Input Field</h3>
<table class="form-table" >
        <th><label for="quote_of_the_day">Quote of the Day</label></th>
            <?php if ( current_user_can( 'administrator' ) ) : ?>

                <input type="text" name="quote_of_the_day" value="<?php echo $quote ?>" class="regular-text" />

            <?php else : ?>

                <?php echo $quote ?>

            <?php endif ?>


add_action( 'show_user_profile', 'wpse_230369_quote_of_the_day', 10 );
add_action( 'edit_user_profile', 'wpse_230369_quote_of_the_day', 10 );

function wpse_230369_save_quote_of_the_day( $user_id ) {
if ( isset( $_POST['quote_of_the_day'] ) && current_user_can( 
'administrator' ) )
    update_option( 'quote_of_the_day', sanitize_text_field( wp_unslash( 
$_POST['quote_of_the_day'] ) ) );

add_action( 'edit_user_profile_update', 'wpse_230369_save_quote_of_the_day' );
add_action( 'personal_options_update',  'wpse_230369_save_quote_of_the_day' );

I inserted Echo just below the input, it works correctly, I just need to display in single.php

enter image description here

  • Where do you want to add it in the single.php ? You're using an option in a user profile, be careful. It will be erased for all if only one user (admin in your case) update it. – Elex Jun 16 '18 at 17:46
  • I need to create a field for the user to insert URL fan page. I will insert "<? Php echo $ quote;?>" Into the href. I do not know php, only HTML and css. I can not use plugin, because I will make theme available for download. Thank you brother! – Wellington Jun 16 '18 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.