Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:35:05+00:00 2026-06-12T13:35:05+00:00

I’m building a custom WordPress theme and have a quick question regarding WordPress and

  • 0

I’m building a custom WordPress theme and have a quick question regarding WordPress and the Functions.php

I’ve got 500 lines of jQuery that run for a portion of my custom theme admin panel. The jQuery code is located inside of my functions.php file, called when the custom admin menu page is displayed.

Ideally, I would like to move the JavaScript out of the functions.php file and use wp_register_script + wp_enqueue_script, but I also have some php code mixed in with the script. See below:

//Function that Provides Options within the Menu Page
function quz_custom_theme_options(){
  global $quz_default_colors, $quz_default_fonts;

    ?>

   <style type="text/css">';

    <?php   include('admin-style.php'); ?>

   </style>';



<script type="text/javascript">
function asf_toggle_box(element)
{
  if (jQuery(element).next('.expandable').is(':visible') )
  {
    jQuery(element).next('.expandable').fadeOut('slow', function(){
      jQuery(element).val('+ Settings');
      jQuery(element).next('.expandable').find('.indicator').val('');  
    });
  } else {
    jQuery(element).next('.expandable').fadeIn('slow', function(){
      jQuery(element).val('- Settings');
      jQuery(element).next('.expandable').find('.indicator').val('visible');  
    });
  }
}

Example of PHP inside of js

function quz_reset_colors(t)
  {
    var theme_name = jQuery(t).attr('id').substr(6);
    var color_fields = jQuery(t).parent().find('div.color_admin_area').find('.color-input-wrap > input[type="text"]');
    // jQuery(color_fields).css('border', '1px solid red');
    // console.log(color_fields);
    var colors = new Array();
    <?php
    foreach ($quz_default_colors as $key => $value)
    {
      echo 'var ary = new Array(\'' . implode('\',\'', $value) . '\');' . "\r\n";
      echo 'colors[\'' . $key . '\'] = ary;' . "\r\n";
    }
    ?>
    jQuery(color_fields).each(function(index, elem){
      jQuery(elem).val(colors[theme_name][index]);    
    });

What is the best way to handle this? Should I just put all the JS in a separate php file and use include('my_script.php'); Like I’ve done with the CSS in the above statement?

I have multiple ways of making this work, but I want to do it the BEST way. Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:35:06+00:00Added an answer on June 12, 2026 at 1:35 pm

    I do a small trick to do this in my Easy Retweet WordPress Plugin.

    // Enqueue the script
    add_action('template_redirect', 'add_script');
    
    function add_script() {
        wp_enqueue_script('retweet', get_option('home') . '/?retweetjs');
    }
    
    add_action('init', 'deliver_js');
    
    function deliver_js() {
        if ( array_key_exists('retweetjs', $_GET) ) {
    
            header('Content-Type: text/javascript');
            print_retweet_js($options);
    
            // die after printing js
            die();
        }
    }
    
    function print_retweet_js($options) {
         include_once('path/to/your/js/script.php');
    }
    

    Hope this is useful to you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.