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 :
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”
http://www.php.net/json_encode
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:
In your .php file: