Jump to content


Photo
- - - - -

Adding a hook to a certain page


  • Please log in to reply
4 replies to this topic

#1 grahamd79

grahamd79

    Advanced Member

  • Members

  • 54 posts
  • Country: Country Flag

Posted 07 May 2012 - 05:38 PM

Hi, Please let me know how to add a hook (html or php based) to a certain page...lets say...to a home page. I have added a hook successfully but that code snippet is displayed on all pages. How to limit the hook to be shown on just a home page? Thanks, Farhan

#2 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 07 May 2012 - 06:42 PM

WordPress has built in template conditionals:

Please Login or Register to see this Hidden Content



#3 grahamd79

grahamd79

    Advanced Member

  • Members

  • 54 posts
  • Country: Country Flag

Posted 08 May 2012 - 04:56 AM

Thanks for your reply, Actually following is the code i wrote for my hook: ---------- if (is_front_page()) { add_action('pagelines_before_main', 'banner_me'); function banner_me() { ?>

#4 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 08 May 2012 - 12:34 PM

The conditional should be inside your function like this:

Please Login or Register to see this Hidden Content



#5 grahamd79

grahamd79

    Advanced Member

  • Members

  • 54 posts
  • Country: Country Flag

Posted 08 May 2012 - 05:47 PM

great...it worked... :)