Jump to content


hooks and php code


This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1 Guest_Ray_*

Guest_Ray_*
  • Guests

Posted 30 April 2011 - 04:27 PM

I have a need to have custom php code on all pages before anything is displayed. In several other frameworks, there are hooks which include "pre header" and others. I can't find anything like that in builder. Does something like this exist? How would one add php code to each page to do some database lookups and other functions before the page starts loading? I've narrowed my choice of frameworks down to builder and catalyst. Catalyst includes the hooks I need, but I like builder better. But liking it better doesn't get the job done if it won't do what I need.

Thanks.

#2 Sridhar Katakam

Sridhar Katakam

    Advanced Member

  • Members
  • Others: Toolkit
  • 22,258 posts

Posted 30 April 2011 - 09:35 PM

Builder does provide a text area in which code to be inserted between <head> and </head> can be added.

For an example, see http://ithemes.com/wp-content/uploads/2010/12/enable-google-analytics-540x358.png

(below the highlighted area)

Edited by Sridhar Katakam, 30 April 2011 - 04:36 PM.


#3 Randy Robinson

Randy Robinson

    New Member

  • Members
  • 2 posts

Posted 02 May 2011 - 03:52 PM

I'm not sure if putting this php code INSIDE the header will or won't mess up the format of the page. The header is the place for javascript. Is there any other place to put php code?

Failing this, could I safely add my code to the header.php?

#4 Ronald

Ronald

    Forum Admin

  • Administrators
  • Others: All Plugins, All Themes, Moderators, Webdesign
  • 28,595 posts

Posted 02 May 2011 - 04:25 PM

Hi,

you can always safely add code to header.php, as long as you make sure to use a child theme, and make such modifications in the header.php file in the child theme folder.

Using the functions.php file, and the standard WordPress wp_enqueue_script function, you can add (external) javascript to your site.

And it depends on the php code that you need to insert. Do you need to add the code inside the <head> section of your site, or if it should be executed before pages display (as you say), but contains html code that should go in the <body> section of your site.

Ronald

Join the iThemes Builder Community on Google+.



To ensure that we can process your support request efficiently, ALWAYS include a link to your site, and/or the page your request is related to. Please also read the forum guidelines.



When asking your question/posting your request on the forum, please be as concise and specific as possible. The shorter your request, the more to the point, the more specific, the easier it will be for us to try and help out.


#5 Randy Robinson

Randy Robinson

    New Member

  • Members
  • 2 posts

Posted 03 May 2011 - 03:40 PM

Some of our code would gather data from databases and display, and as far as I can tell, we can do that within a page with the html module.

But some of the code needs to grab a REQUEST variable from the URL or a form which sent the person to the site and save a cookie which we have to look up when someone signs up for membership (to have the source of each member). It's possible that based on this variable, the page that opens may vary which is why it can't be done after the page has loaded. Will code in header.php do this?

#6 Ronald

Ronald

    Forum Admin

  • Administrators
  • Others: All Plugins, All Themes, Moderators, Webdesign
  • 28,595 posts

Posted 04 May 2011 - 02:24 AM

Hi,

if you can get this to work in a WordPress theme, you can also get it to work in Builder. I suggest you try adding your code and functionality using the default twenty-ten theme, and if that works fine, I see no reason why it should not work in Builder.

If you want particular support on Builder, please post in the Builder support forum.

Ronald

Join the iThemes Builder Community on Google+.



To ensure that we can process your support request efficiently, ALWAYS include a link to your site, and/or the page your request is related to. Please also read the forum guidelines.



When asking your question/posting your request on the forum, please be as concise and specific as possible. The shorter your request, the more to the point, the more specific, the easier it will be for us to try and help out.