1

I want add some PHP code to the head of a template, but I am unsure as to how to achieve this.

I've tried adding the following to my index.php but it doesn't work:

<?php  
class __AntiAdBlock_
{
    private $token = '999';
    private $zoneId = '12';
    ///// do not change anything below this point /////
    private $requestDomainName = 'go.transferzenad.com';
    private $requestTimeout = 1000;
    private $requestUserAgent = 'AntiAdBlock API Client';
    private $requestIsSSL = false;
    private $cacheTtl = 30; // minutes
    private $version = '1';
    private $routeGetTag = '/v3/getTag';
    private $selfSourceContent;

    private function getTimeout()

}
$__aab = new __AntiAdBlock_245();
return $__aab->get();

In which file of the Gantry (Helium) template should I be adding this code?


thanks but i can not add " php code " with your help :

i need more help ! please step to step help me how add php code in template of joomla (gantry template ), please show with image step to step!

i see this link : http://docs.gantry.org/gantry5/advanced/php-functions#overriding-the-themephp-file

but my folder & file is defernet & i can not fond main folder with main " php file for add code (tag ) to work ! thank you


i use of some module for add code but do not work & i install direct php how add code to gantry template ?

so core joomla is not "php " so gantry template work on php !?

so what is main php file for this template & where ?

how i can add code direct ?!

or we must use of module so there is not default module for this work ?

please help me . thank you

4
  • Welcome to JSE. The template dictates the design of a website. You shouldn't be adding PHP in there. Instead, create a Joomla plugin
    – Lodder
    Apr 20, 2019 at 14:16
  • @hojjat we may need to better understand your task with more context. Right now your issue may be Too Broad for volunteers to concisely/specifically resolve. Apr 21, 2019 at 6:27
  • Might you, most directly, be interested in an anti adblocking plugin? A quick JED shows extensions.joomla.org/extension/system-ad-block-reactor and others. Apr 21, 2019 at 11:57
  • @hojjat a "good" question will look a bit like this... "I followed this {hyperlink} tutorial / online documentation, I tried to implement it like this {code block}, but I didnt get the desired result of {exactly what you want}. These parts worked {list of successful pieces/variables/etc}. These errors were generated: {list of full error messages while in debugging mode or from error log}. Here is a screen shot of what I am currently printing to screen {screenshot}." If you don't know how to debug / isolate your issue, research how, then ask for help about how to debug. Apr 22, 2019 at 22:34

2 Answers 2

2

Gantry5 makes it easy to add HTML/CSS/JS to the head within the Page Settings on the Base Outline (or a specific one). http://docs.gantry.org/gantry5/configure/page-settings#head-properties

However, PHP would probably be best into the includes/theme.php file: http://docs.gantry.org/gantry5/advanced/php-functions#overriding-the-themephp-file

You might consider packaging up your code into a System Plugin.

1
  • Easy to add code in the page settings, but it will be added at the bottom. Some code (cookie banner) needs to go on the top. Editing the Gantry theme.php looks rather complicated if you don't already have those particular coding skills ... system plugin? Who's got budget for that. Adding code to the head should be a 3 minute business.
    – Ralf
    Aug 22 at 8:40
0

Editing the template code directly is not considered best practice as future template updates may overwrite your changes.

A better approach might be to use a third party extension. There is likely something suitable in the Joomla Extensions Directory at http://extensions.joomla.org/category/core-enhancements/coding-a-scripts-integration

6
  • While I am sure that the whole community appreciates your support and I know that there are many historical answers that post links to extensions / the JED, the Stack Exchange Network does not aspire to be a "traffic router". Apr 21, 2019 at 6:24
  • Right now your answer is saying, "don't do it that way, go to this link". This doesn't make you a bad contributer, but the post is effectively a Link-only Answer (which is considered low-value). If your support can be edited to provide a hardcoded solution (that doesn't rely on a link), please do so. If the question is too vague to provide a narrow/specific solution, that probably indicates that the question is Too Broad, Unclear, or Off-topic - because it requires hands on professional assistance. Apr 21, 2019 at 6:25
  • JSE should be the final stop for seeking solutions, not a waypoint. I am leaving this comment because I don't want to maintain the status quo; I want to raise the quality of the content in this community because everyone benefits if we do so. Apr 21, 2019 at 6:25
  • 2
    Hi Mick, I am promoting best practice and link to a JED category which hopefully will have more longevity than linking to a specific extension (which admittedly may come or go). Links to the JED should be allowed here as the JED is likely to exist as long as the Joomla project itself. If pushed, I could probably come up with a coded solution but why reinvent the wheel if there is already a proven and tested solution in the JED? The question and answers at joomla.meta.stackexchange.com/q/105/120 do not seem to indicate there is any issue with posting links to the JED. Apr 21, 2019 at 8:35
  • 1
    To me, the question seems clear and specific. I don't see any problem with it personally. Apr 21, 2019 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.