[Resolved] Add PHP and JS code in elements

Home Forums Support Add PHP and JS code in elements

  • This topic has 5 replies, 3 voices, and was last updated 1 year ago by Tom.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #991894
    Alejandro

    Hi !
    I need to add PHP and JS code in my site, but i was reading when the theme is upgraded, the code added into functions.php archive will delete. So, If I add the codes in Elements hooks, They will work good when the theme upgrade, or the codes will be deleted too?
    I dont really create a child theme and i need to know if i can use in a safe way elements hooks !

    Thanks.

    #991946
    David
    Staff
    Customer Support

    Hi there,

    JS Code: no problem adding them to a Hook.
    PHP Code: This will depend on what that code does. For example if it is calling a template part then all should be fine. If its a Filter Hook function then no, this needs to go in child theme functions file or you can use the Code snippets plugin

    #992253
    Alejandro

    Great ! So, i have two options:

    1 – If I add JS or for example google analytics or tag manager codes in the hooks on elements, those codes will not be deleted with de upgrade theme, and can i add a snippets plugin with out a child theme?

    2 – Can i create the child theme, add the PHP code with out plugin and copy the JS in the element’s hooks but working with the child theme?

    Which of them are better?
    I dont know if if you understood me ! Thanks for the support.

    #992573
    Tom
    Lead Developer
    Lead Developer

    Both of those options will work. Whether you use a child theme or not is really your preference. A child theme becomes necessary if you need to overwrite core template files.

    If you already have a child theme, using the functions.php file for functions is the way to go. Elements is a good place to add your analytics/Google manager code regardless of a child theme or not.

    #993355
    Alejandro

    Thank you so much for the support ! All of you really helped me.

    #993896
    Tom
    Lead Developer
    Lead Developer

    No problem! Glad we could help 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.