Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

GUIDE:: add_to_head & add_to_footer

Asked Modified Viewed 9,858 times
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
  • Started this discussions
asked
Fusioneer

GUIDE:: add_to_head & add_to_footer

There is no need to edit your actual header.php or footer.php files.

Simply use the add_to_head and add_to_footer functions to insert your script or css codes.

We can do it all through panels by adding the add_to_head / add_to_footer function with your code into the panel editor.

add_to_head for adding code to the header is simply used like this...

add_to_head("Code Here");


add_to_footer is used the same like this...

add_to_footer("Code Here");


Sometimes Javascript is needed to be added to the header or css so we just simply do this...

Example for CSS...

add_to_head("<style type='text/css'>
#a_class_id {
      border-radius: 4px 4px 4px 4px;
      -moz-border-radius: 4px 4px 4px 4px;
      -webkit-border-radius: 4px 4px 4px 4px;
      display: block;
      padding: 5px 0;
      width: 100%;   
}
</style>");


Or maybe you just need to add the css style link to the header like this we would do it...

add_to_head("<link href='infusions/a_panel/includes/fstyle.css' media='screen, projection' rel='stylesheet' type='text/css' />");


this would be the same if you need to add javascript to the header simply do this...

add_to_head("<script type='text/javascript' src='/some_jsscript.js'></script>");



If you need to add javascript code it is best to add that to the footer.
We will use add_to_footer for that.
Example, Google Analytics's should be added to the footer so we use the add_to footer function like this...

add_to_footer("<script type='text/javascript'>

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345678-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>");


Using these 2 functions makes life for developers/coders/web masters a whole lot easier and if we upgrade to the next php-fusion we will not have any problems because we did not modify any core files.

Simply use the functions and paste your code into a panel and enable it.
Use the Google Analytics one as an example, paste it into a new lower center panel and enable it on all pages.
View your page source look down at the footer you will see your Google Analytics code there.
Edited by Craig on 07-06-2012 16:57,
0 replies

6 posts

O
outlaw16151
O
  • Member, joined since
  • Contributed 88 posts on the community forums.
  • Started 6 threads in the forums
answered
Member

i tried it, it threw an error for add_to_footer
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
  • Started this discussions
answered
Fusioneer

Hi there,

What did you try?

Please provide code so I can learn the issue?

What does the Error log say about it?

Kind Regards
Craig
0 replies
O
outlaw16151
O
  • Member, joined since
  • Contributed 88 posts on the community forums.
  • Started 6 threads in the forums
answered
Member

<script type="text/javascript">document.write(unescape("%3Cscript src=%27http://s10.histats.com/js15.js%27 type=%27text/javascript%27%3E%3C/script%3E"));</script>
<a href="http://www.histats.com" target="_blank" title="website hit counter" add_to_head("<script  type="text/javascript" >
try {Histats.start(1,1394987,4,0,0,0,"");
Histats.track_hits();} catch(err){};
</script></a>
<noscript><a href="http://www.histats.com" target="_blank"><img  src="http://sstatic1.histats.com/0.gif?1394987&101" alt="website hit counter" border="0"></a></noscript>");


/Code tags done /Richard
Edited by Homdax on 27-02-2013 21:34,
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
  • Started this discussions
answered
Fusioneer

Hi there,

Please use the Code BB Code tags to wrap that code so we don't see any smileys and other stuff.

Please change all " to '

Please do not change the ones at the beginning and end to ' like

add_to_footer("");


Keep them 2 " there but everything in-between must be '


Kind Regards
Craig
0 replies
— 2 years later —
D
dghodge
D
  • Newbie, joined since
  • Contributed 1 post on the community forums.
answered
Newbie

Hello There!

I need to add custom code to the <head> .... </head> of a CUSTOM page. Where do you insert the add_to_head function? I can't figure it out. Can someone help?

Thanks in advance.
0 replies
D
dimki
D
dimki 10
  • Senior Member, joined since
  • Contributed 246 posts on the community forums.
  • Started 28 threads in the forums
answered
Senior Member

themes  +templates  +  header.php    for  this  echo "</head>\n<body>\n";            add_to_head("your  code   hiar ");     Please change all " to '




or


your   in theme   theme.php   in top     this  add_to_head("your  code   hiar ");     Please change all " to '  




for example differently <<<< Google Analytics



echo "<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', ' code hiar ....', 'auto');
  ga('send', 'pageview');

</script>\n";

Edited by dimki on 21-05-2015 13:49,
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 6 posts
  • Votes 0 votes
  • Topic users 4 members

4 participants

C
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
  • Started this discussions
D
D
dimki 10
  • Senior Member, joined since
  • Contributed 246 posts on the community forums.
  • Started 28 threads in the forums
O
O
  • Member, joined since
  • Contributed 88 posts on the community forums.
  • Started 6 threads in the forums
D
D
  • Newbie, joined since
  • Contributed 1 post on the community forums.

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet