Using php inside wordpress

Discussion in 'PHP' started by hamzasiddiq1995, Mar 12, 2014.

  1. #1
    Topic edit:Using php inside javascript in wordpress

    I have got the following code in a javascript file called custom.js:

                blabla = new Date(2014, 06 - 1, 2);
                $('.days').countdown({
                until: blabla,
                layout: '{dn} {dl}',
    Code (markup):
    1.Now i want a user to be able to change the above date. I have created a theme options page called theme-options.php

    2.I am using <?php require_once('theme-options.php'); ?> in the functions.php to link to theme-options.php.

    3.This is theme-options.php:
    <?php
    add_action('admin_menu', 'director_create_menu');
    function director_create_menu() {
    add_submenu_page( 'themes.php', ' Theme Options',
    'Theme Options', 'administrator', __FILE__,
    'director_settings_page');
    add_action( 'admin_init', 'director_register_settings' );
    }
    function director_register_settings() {
    register_setting( 'director-settings-group', 'director_date' );
    }
    
    div class="wrap">
      <h2>Theme Settings</h2>
      <form id="landingOptions" method="post" action="options.php">
        <?php settings_fields( 'director-settings-group' ); ?>
        <table class="form-table">
    <tr valign="top">
              <th scope="row">Date:</th>
              <td>
                <input type="text" placeholder="2014, 06 - 1, 2" name="director_date"
                value="<?php print get_option('director_date');
                ?>" />
              </td>
            </tr>
    <p class="submit">
            <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
            </p>
          </form>
        </div>
        <?php } ?>
    
    
    Code (markup):
    Basically what is happening is that there is a theme options page.A user gives a date inside it. Now i want to use that date inside the javascript file.
    If I had to use it inside index.php it would've been
    <?php $date = get_option('director_date'); ?>
    <?php if( $date ) : ?> <?php echo $date; ?><?php endif; ?>);. However this is javascript. How do i implement such an action here?
     
    Last edited: Mar 12, 2014
    hamzasiddiq1995, Mar 12, 2014 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,897
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    That javascript is jquery - it has built in ajax to call a serverside script but it's not really clear what you are trying to do.

    Generally if you want to run PHP inside WordPress you'd write a plugin and javascript might be a part of that... but despite your heading it doesn't appear to be what you are trying to do.
     
    sarahk, Mar 12, 2014 IP
  3. hamzasiddiq1995

    hamzasiddiq1995 Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #3
    Hi sarahk the topic name was by mistake. It should've been "Using php inside javascript in wordpress".I am sorry about that i am new here and don't know how to edit the topic. Anyhow have a look at the edited question
     
    Last edited: Mar 12, 2014
    hamzasiddiq1995, Mar 12, 2014 IP