arjanv Posted December 22, 2012 Share Posted December 22, 2012 I want a enable/disable option in my wordpress theme admin panel to enable or diable the main navigation menu. I know how to do this using php, but i need to make a change some javescript code in a .js file. but how to do this with php. i mean i have allready made the option in the theme adminpanel php file availeble, but it needs to do something in a .js file. i hope you understand what i mean. portion of the themoptions file: $dd_options[] = array( "name" => __("nav menu", "dd"), "desc" => __("Enable / Disable navigation menu", "dd"), "id" => "nav_menu", "std" => "1", "type" => "checkbox"); --------------------------------------------------------------- header.php: <?php if(!empty($nav_menu)) { ?> <?php if ( has_nav_menu( 'headermenu' ) ) { ?><?php wp_nav_menu ( array( 'menu_id' => 'nav','container'=> 'ul', 'theme_location' => 'headermenu' )); ?> <?php } else { ?> nothing <?php } ?> --------------------------------------------------------------- theme.js file: ddsmoothmenu.init({ mainmenuid: "menu", //menu DIV id orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v" classname: 'navigation', //class added to menu's outer DIV //customtheme: ["#1c5a80", "#18374a"], contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] }) when i disable the menu it must disable the whole ddsmoothmenu in the javascript file. but how to do this? i'm a bit lost. Quote Link to comment https://forums.phpfreaks.com/topic/272290-change-javascript-code-from-php/ Share on other sites More sharing options...
Amplivyn Posted December 25, 2012 Share Posted December 25, 2012 As far as I know (I may be wrong), but I don't think you can edit your .js file using php. You may, however, wish to output some .js script/code onto your page, using php, which may include a variable such as var showMenu = true or false. Using this, you can write code in your .js file to show your menu or not. Just be careful of declaring this variable before you run the menu code. This is also one way of doing things but may not be the best, in any case, good luck! Quote Link to comment https://forums.phpfreaks.com/topic/272290-change-javascript-code-from-php/#findComment-1401258 Share on other sites More sharing options...
Psycho Posted December 26, 2012 Share Posted December 26, 2012 (edited) This is actually quite easy. You just need to do the following: 1. Change the .js file to a php file. Then change all of the javascript src attributes to use the newly named file. (Note: the file used for a javascript src does not need to be .js - it can be anything) Now, when the HTML page loads and attempts to load the content it will be loading a php file instead so you have full control over the content returned. 2. In the newly renamed PHP file put in whatever logic you want to include/remove certain line of code Edited December 26, 2012 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/272290-change-javascript-code-from-php/#findComment-1401266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.