WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Java script support on my Theme options page (4 posts)

  1. Rakesh Raja
    Member
    Posted 1 year ago #

    Hi

    I am creating theme options page.. I want to use jquery tabs for sections .. I need to use following code.. but its not working in admin

    <script type="text/javascript">// <![CDATA[
    
    			$(document).ready(function () {
    				$('.wpgpanelmenu').tabify();
    			});
    
    			// ]]>
    </script>

    Any idea how can I run it? or any other way?

  2. It may be how you are inserting the code. Have you reviewed this article?

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

  3. Rakesh Raja
    Member
    Posted 1 year ago #

    That I have done already for actual .js files

    wp_enqueue_script( 'theme-options', get_template_directory_uri() . '/wpgpanel/js/jquery.js' );
    wp_enqueue_script( 'theme-options', get_template_directory_uri() . '/wpgpanel/js/jquery.tabify.js' ); ?>

    But to make tabs work.. I need to add above code directly in theme options file.. and its not working

    <script type="text/javascript">// <![CDATA[
    
    			$(document).ready(function () {
    				$('.wpgpanelmenu').tabify();
    			});
    
    			// ]]>
    </script>
  4. Rakesh Raja
    Member
    Posted 1 year ago #

    Here is solution, Now you can use any jQuery or javascript code in your theme options page

    Just make sure you add following action before you load your options page data..

    add_action('admin_print_scripts', 'my_admin_head_script');

    Right after it create functions we used above and add all your code and javascripts there.. thats it!

    <?php function my_admin_head_script() { ?>
    
    <script src="<?php echo get_template_directory_uri() . '/wpgpanel/js/jquery.js'; ?>" type="text/javascript" charset="utf-8"></script>
    <script src="<?php echo get_template_directory_uri() . '/wpgpanel/js/jquery.tabify.js'; ?>" type="text/javascript" charset="utf-8"></script>
    
    <script type="text/javascript">// <![CDATA[
    
    			$(document).ready(function () {
    				$('.wpgpanelmenu').tabify();
    			});
    
    			// ]]>
    </script> 
    
    <?php } ?>

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic