Jump to content

Change Javascript Code From Php


arjanv

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.