I have the following php pages main.php content.php  main.php  When the user clicks a link the content.php page is loaded in a div in main.php page.The main.php when loaded contains a separate script file that has scripts for content.php page. The script works fine when I include it in the content.php but does not work when i place it in a separate file in the head section of main.php What is the reason for this?  JS File  $(function(){     $('#new').click(function(event){         event.preventDefault();         $('#content').load('content.php');     });     $('#rank').click(function(event){         alert("This works!!");         event.preventDefault();     }); });   main.php   &lt;div id="container"&gt;             &lt;div id="header"&gt;             &lt;/div&gt;             &lt;div id="nav"&gt;                &lt;a href="#" id="new"&gt;New Page&lt;/a&gt;             &lt;/div&gt;             &lt;div id="content"&gt;     /*** Pages get loaded Here ***/             &lt;/div&gt;             &lt;div id="footer"&gt;             &lt;/div&gt;         &lt;/div&gt;   content.php  &lt;a href="#" id="rank"&gt;jQuery Test&lt;/a&gt;
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
92703
I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see frontend requests go through "/wp-admin/". No practical reason, just looks ugly IMO.)  So I've simply copied admin-ajax.php to the root dir at "/ajax.php", adjusted the include paths and removed the WP_ADMIN constant definition. Seems to work like gangbusters (I can now just direct all my frontend AJAX requests to /ajax.php! And I can still use the normal wp_ajax hooks in my plugins!).  But is this safe? What might go wrong? Since this isn't built into core, I assume there's a good reason as to why not. But looking through the code, I can't see any immediate problems.   You're smart--tell me if this approach is crazy. Or if there's a simpler method that I'm overlooking.
48263
I'm fixing a wordpress plugin that uses a 1.0.0 version of jquery. The jquery version automatically included in wordpress is 1.11.0. In a test site, the plugin is dependent on the 1.0.0 jquery and doesn't work on the latest version.  However, it works on a test site because the plugin is loaded BEFORE the wp-includes/js/jquery/jquery.js and it uses it's own jquery library version before the script is overwritten by the latest jquery version. It doesn't produce any errors in the console.  But in the production site, it loads all the plugins after the wp-includes/js/jquery/jquery.js So, how do I force the plugin to load, before wordpress loads the wp-includes/js/jquery/jquery.js file?  This is the code in the plugin:  add_action('init', 'myplugin_init');  function myplugin_init() { wp_enqueue_script('jquery.min', plugins_url(MYPLUGIN_FOLDER . '/js/jquery.min.js'), array(), '1.0.0', false); wp_enqueue_script('highcharts', plugins_url(MYPLUGIN_FOLDER . '/js/highcharts.js'), array(), '1.0.0', false); wp_enqueue_script('exporting', plugins_url(MYPLUGIN_FOLDER . '/js/exporting.js'), array(), '1.0.0', false); }   I already tried, for testing purposes, to force the enqueue of plugin scripts right before wp_head(); but it still loads the plugin files AFTER the wp-includes/js/jquery/jquery.js.   &lt;?php     wp_enqueue_script('jquery.min', plugins_url(MYPLUGIN_FOLDER . '/js/jquery.min.js'), array(), '1.0.0', false);     wp_enqueue_script('highcharts', plugins_url(MYPLUGIN_FOLDER . '/js/highcharts.js'), array(), '1.0.0', false);     wp_enqueue_script('exporting', plugins_url(MYPLUGIN_FOLDER . '/js/exporting.js'), array(), '1.0.0', false);  wp_head();     ?&gt;   Any help is much appreciated. Thanks.
24574
I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.  What is the general practice for this?  Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I include on all these pages. But the question is, do I:   write the bits of code that configure this script inline? include all bits in one file that's share among all these html pages? include each bit in a separate external file, one for each html page?   Thanks.
37551
I want to load the new entries without reloading the page. I found a great solution for: The ajax script:  &lt;script&gt;     $(document).ready(function() {     var refreshId = setInterval(function()     {         $('#content').fadeOut("fast").load('http://neocsatblog.mblx.hu/new.php').fadeIn("fast");     }, 10000);      }); &lt;/script&gt;   And the php:  &lt;?php require_once("wp-blog-header.php"); ?&gt; &lt;div id="content" &lt;?php cyberchimps_filter_content_class(); ?&gt;&gt;          &lt;?php do_action( 'cyberchimps_before_content'); ?&gt;          &lt;?php if ( have_posts() ) : ?&gt;              &lt;?php while ( have_posts() ) : the_post(); ?&gt;                  &lt;?php get_template_part( 'content', get_post_format() ); ?&gt;              &lt;?php endwhile; ?&gt;          &lt;?php elseif ( current_user_can( 'edit_posts' ) ) : ?&gt;              &lt;?php get_template_part( 'no-results', 'index' ); ?&gt;          &lt;?php endif; ?&gt;          &lt;?php do_action( 'cyberchimps_after_content'); ?&gt;      &lt;/div&gt;   However, this is a special feature that works perfectly here:  However, the main page refuses to load new entries, I do not understand the reason for this, as we use everything the same.
35211
I have an odd problem...I'm using a documentation generator which generates a lot of output like docs/foo.php.html. It's XHTML, and thus contains &lt;?xml...&gt; tags at the beginning of file. The problem is, Apache has somehow decided to run it through the PHP interpreter, even though ".php" appears in the middle of the filename, and not at the end. This, in turn, triggers a PHP error, because it sees "&lt;?" as the command to start executing PHP code, and immediately gets confused by the "xml..." which follows it.  How do I configure Apache to ONLY execute .php files and not .php.html files? The string "php.html" does not appear explicitly anywhere in my Apache config files. There is a line "AddHandler php5-script .php", but I don't see how that would also include ".php.html" files.
46669
I have two simple functions that load stuff using  and , something like these:  function admin_custom_css() { wp_enqueue_style( 'stylesheet_name', 'stylesheet.css') };   function admin_custom_js  { wp_enqueue_script( 'javascript_file', 'script.js') };   ... and a few admin pages, created with  and   function my_menu() {    add_menu_page('Page 1', 'bar', 'something', 'else', 'foo');    add_submenu_page( 'theme_menu', 'Subpage 1', 'Subpage', 'something', 'else', 'foo');  } add_action('admin_menu', 'my_menu');    How do I load my two functions only on these pages?  Right now I'm using:  add_action('admin_init', 'admin_custom_css' );  add_action('admin_init', 'admin_custom_js' );     But it loads my files on every admin page, which is not nice at all.  Can I do this via one simple line in functions.php or have to enqueue them within my pages separately (I prefer the first option strongly, since I'd have to edit a lot of admin-page-creating-functions).  Thanks!
120639
I'm trying to put search results into a div with ajax. The issue is I'm getting errors saying undefined function have_posts() when the the search template is accessed. It also took issue with get_header() which was in the search-results.php but I took it out. Here's how I have it setup.    &lt;div id="my_search"&gt;    &lt;form role="search" method="get" id="searchform" action="http://myurl.com/" &gt;     &lt;input type="text" value="" name="s" id="s" /&gt;     &lt;input type="submit" id="searchsubmit" value="Search" /&gt;    &lt;/form&gt;   &lt;/div&gt;   &lt;div id="results"&gt;&lt;/div&gt;   &lt;script type="text/javascript"&gt;     $(document).ready(function(){     $("#searchsubmit").click(function(e){      e.preventDefault();      var search_val=$("#s").val();       $.post('http://mysite.com/wp-content/themes/beta/search-results.php',{search_string:search_val},function(data){         if(data.length&gt;0){             $("#results").html(data);         }      });     });       });   &lt;/script&gt;   And here is the search-results.php template. I'm wondering if maybe I'm not passing the search results to the template.  &lt;ul&gt;  &lt;?php if (have_posts()) : while (have_posts()) : the_post();  ?&gt;   &lt;li&gt;&lt;a title="Permalink to this post" href="&lt;?php echo get_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;   &lt;?php endwhile; endif; ?&gt;  &lt;?php if (!have_posts()) { echo('&lt;li&gt;No results to show.&lt;/li&gt;'); } ?&gt; &lt;/ul&gt;
16364
How can I reference the script element that loaded the javascript that is currently running?  Here's the situation. I have a "master" script being loaded high in the page, first thing under the HEAD tag.  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;script type="text/javascript" src="scripts.js"&gt;&lt;/script&gt;   There is a script in "scripts.js" which needs to be able to do on-demand loading of other scripts. The normal method doesn't quite work for me because I need to add new scripts without referencing the HEAD tag, because the HEAD element hasn't finished rendering:  document.getElementsByTagName('head')[0].appendChild(v);   What I want to do is reference the script element that loaded the current script so that I can then append my new dynamically loaded script tags into the DOM after it.  &lt;script type="text/javascript" src="scripts.js"&gt;&lt;/script&gt; loaded by scripts.js--&gt;&lt;script type="text/javascript" src="new_script1.js"&gt;&lt;/script&gt; loaded by scripts.js --&gt;&lt;script type="text/javascript" src="new_script2.js"&gt;&lt;/script&gt;
82255
I'm making a page which has some interaction provided by javascript. Just as an example: links which send an AJAX request to get the content of articles and then display that data in a div. Obviously in this example, I need each link to store an extra bit of information: the id of the article. The way I've been handling it in case was to put that information in the href link this:  &lt;a class="article" href="#5"&gt;   I then use jQuery to find the a.article elements and attach the appropriate event handler. (don't get too hung up on the usability or semantics here, it's just an example)  Anyway, this method works, but it  a bit, and isn't extensible at all (what happens if the click function has more than one parameter? what if some of those parameters are optional?)  The immediately obvious answer was to use attributes on the element. I mean, that's what they're for, right? (Kind of).  &lt;a articleid="5" href="link/for/non-js-users.html"&gt;   In  I asked if this method was valid, and it turns out that short of defining my own DTD (I don't), then no, it's not valid or reliable. A common response was to put the data into the class attribute (though that might have been because of my poorly-chosen example), but to me, this smells even more. Yes it's technically valid, but it's not a great solution.  Another method I'd used in the past was to actually generate some JS and insert it into the page in a &lt;script&gt; tag, creating a struct which would associate with the object.  var myData = {     link0 : {         articleId : 5,         target : '#showMessage'         // etc...     },     link1 : {         articleId : 13     } };  &lt;a href="..." id="link0"&gt;   But this can be a real pain in butt to maintain and is generally just very messy.  So, to get to the question, how do you store arbitrary pieces of information for HTML tags?
43338
I am unable to call PHP files inside the Drupal directory. My task is maintaining staff's old pages on the new platform. With pages written on clear HTML, there is no problem: I place files in a folder I created (domain.org/sites/default/files/share/staff_folder).  In sites/default/files/.htaccess I added DirectoryIndex share and now the link to the domain.org/sites/default/files/share/staff_folder/index.html can be used. When I import pages written in PHP, e.g. calling domain.org/sites/default/files/share/staff2_folder/index.php, I get a 403 error:     Forbidden      You don't have permission to access /sites/default/files/share/staff2_folder/index.php on this server.   While /sites/default/files/share/staff2_folder/index.html still works.
114452
I am trying to add JavaScript and CSS files to one node type page from my template.php file but it is not working.  Here is my template.php code:   &lt;?php // $Id: template.php,v 1.13 2010/12/14 01:04:27 dries Exp $  function mttheme_preprocess_html(&amp;$variables) {   $node = node_load(arg(1));   if ($node-&gt;type = 'sales_team_page') {     drupal_add_css('misc/jquery.fancybox-1.3.4.css');     drupal_add_js('misc/jquery.mousewheel-3.0.4.pack.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );     drupal_add_js('misc/jquery.fancybox-1.3.4.pack.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );     drupal_add_js('misc/jquery.fancybox-calls.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );   } }   Does anyone know why it is not working?
4344
Is there a location where I can drop in a custom JavaScript file in Drupal 7.x?  It just includes simple event actions for menus, and I don't want to edit the theme/module files.  Or do I have to just add the "include" hook to the theme/module?
57784
I'm working on a offline version of a website using jQuery and some xml files. I'm running in to a problem in jQuery when I do a $.ajax call on a xml file jQuery throws a error.  When I look at the error I can tell its loading the XML file because its in the error's responceText property. It seams to work just fine in Firefox.  This is how my call looks  $.ajax({     type: "GET",     url: "Modules/" + ModuleID + "/ModuleContent.xml",     dataType: "xml",     success: function(x) { xml = x; ProcessXML(); },     error: function(x) { alert(x.responceText); } });   When I run this on a web server it works just fine. Its only when I run it from the file its self when I have this problem.  Any ideas on how I can make this work in IE?  Edit: I found the answer to my problem.
10878
I add js file with drupal_add_js in hook_form_alter, it is ok and I see it in list of js loaded in page, but when I submit form and form not validate and return to that form (after validation failed) I don't see js files that added to form, why this happened? and how can add my js file in that form after validation failed ?   some part of my code   function mymodle_form_alter(&amp;$form, $form_state, $form_id) {   if ($form_id == 'news_node_form') {     drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodulejsfile.js'); //, array('scope' =&gt; 'footer','weight' =&gt; 10));   } }   code work correctly in add and edit form, but when form submit and validation failed it show validation error but my js file not loaded in page (I checked html source and check firebug script files), but there is not my js file,
87186
For the following pretty straightforward task: query a list of products from a DB and present it on a webpage, consider 2 setups:  Setup1: PHP script queries. All content is built on the server and the entire page is served back to the client.  Setup2: Static HTML "page skeleton" requesting content using AJAX. Received content is parsed on the client side using Javascript and rendered using innerHTML or similar.  Of course the second setup only makes sense when you have pages, categories and tags for the client user to choose from.  I need to compare these two, at least by means of:   time it will take content to be served user experience (setup1 is delivered as a whole, setup2 is delivered in "two parts") scalability - how do the setups compare when I have 100,000 queries daily   Any thoughts on the issue will be much appreciated.
33938
I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?  Here is an example script that does not work on my hosts' server as of right now:  &lt;?php session_start(); if(isset($_SESSION['views']))     $_SESSION['views'] = $_SESSION['views']+ 1; else     $_SESSION['views'] = 1;  echo "views = ". $_SESSION['views']; echo '&lt;p&gt;&lt;a href="page1.php"&gt;Refresh&lt;/a&gt;&lt;/p&gt;'; ?&gt;   The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a  problem on their side, but I wanted to make sure I'm not a complete idiot first.  Here is the phpinfo() for my hosts' server (PHP Version 4.4.7):