Wordpress functions file code corrupting WP-Admin!

Discussion in 'PHP' started by Daniel Hutchinson, Mar 28, 2014.

  1. #1
    Hi everyone,

    I'm using wordpress to create a blog for a static website and have come across something i can't figure out.

    I'm attempting to insert javascript code into my functions.php file of a theme i have created and when i do, although the javascript works and gives me the desired outcome on my site (a rollover image effect for buttons), it also causes wordpress to output the 'white screen of death' when i update anything through wp-admin.

    <head>
    <script type= "text/javascript">
    
    
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    </script>
    </head>
    
    <?php
    
    ?>
    PHP:

    Should i not be attempting to insert javasript in the functions.php file?

    I understand that google is out there with a wealth of answers, but i still can't figure this one out after looking.

    Im relatively sure it's a simple fix, but i lack the php/javascript knowledge to do it. The reason i have gone for javasript to achieve the rollover effect with my images is simply because that's the code Dreamweaver used when creating the static side of the site.

    Thanks for reading, and thanks for your help.

    Dan
     
    Daniel Hutchinson, Mar 28, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    I would try to remove the <head> tags, and also, if that doesn't work, try putting the <script> in index.php instead of functions.php
     
    PoPSiCLe, Mar 28, 2014 IP
  3. Daniel Hutchinson

    Daniel Hutchinson Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    Moving the script out of functions.php to the head tags in index.php has fixed the problem.

    I thought it would be obvious.

    Thanks!
     
    Daniel Hutchinson, Mar 28, 2014 IP
  4. Daniel Hutchinson

    Daniel Hutchinson Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    ...scrap that.

    Apologies, I thought it was solved as the javascript continued to work when moved to the index file, but the problem remains that when i have a functions.php file uploaded (with no javascript) it causes that 'white screen of death'.

    It appears that it's not the javascript that was crashing the wp-admin. It's simply the blank functions.php file.

    Any thoughts on what could be causing this?
     
    Daniel Hutchinson, Mar 28, 2014 IP
  5. bhuthecoder

    bhuthecoder Member

    Messages:
    245
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    43
    #5
    you need to use hooks for inserting javasript in the functions.php file.
    Remove any white spaces before php opening tags and after php closing tags in functions.php file
     
    bhuthecoder, Mar 28, 2014 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Normally functions.php is not originally blank - at least not completely blank - are you sure you haven't deleted something that was there by accident?
     
    PoPSiCLe, Mar 30, 2014 IP