Jquery read <?php echo get_option(‘value’); ?> and not the value

This is the php function present in function.php :

<?php
add_action('admin_menu', 'baw_create_menu');
function baw_create_menu() {
    add_menu_page('Bubbles', 'Bubbles', 'administrator', __FILE__, 'baw_settings_page');
    add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
    register_setting( 'baw-settings-group', 'category' );
}
function baw_settings_page() {
?>
<div class="wrap">
<form method="post" action="options.php">
    <?php settings_fields( 'baw-settings-group' ); ?>
    <?php do_settings_sections( 'baw-settings-group' ); ?>
    <textarea style="width:400px" name="category"><?php echo get_option('category'); ?></textarea>

    <?php submit_button(); ?>
</form>
</div>
<?php } ?>

And I want to get the string :

Read More
  var category = "<?php echo get_option('category'); ?>";
  alert(category);

But the alert gives me my php code: <php echo get_option ('category');?> And not the string such as “banana”

Related posts

Leave a Reply

2 comments

  1. PHP cannot be parsed in a .js file. You need to create a function in your .js file and pass in the string returned from PHP:

    function fromPHP(phpString) {
        var category = phpString;
        alert(category);
    }
    

    In your .php file:

    fromPHP(<?php echo json_encode(get_option('bulle_index_1')); ?>);