I want to insert a script to a Drupal page. What I can find there's no footer.tpl.php or head.tpl.php. I can find the page.tpl.php and tried to insert the script there but with no luck. I just want to add the script to a specific page therefore I tried to hard code it into the body of that page but with no luck. Where do I insert a script tag, there's to themes installed as far as I know and it's Base and Garland.
Thanks!
The usual way of adding javascript to a page is using drupal_add_js. By default, if you specify a file to add, it will add it in the section of the markup.
reallyxloco is correct about using drupal_add_js to add your script. What you'd need to do is add that into your template.php file.
The tpl file that you are probably trying to locate is likely html.tpl.php but depending on your version of Drupal, that might be a core file.
I'm trying to use drupal_add_js and it works. The thing is for the script to work it has to be inserted in the footer which also works, but drupal adds a slash in front of the src like this "/http://www.example.js", trying to say that the script is a external script but without no success, here's the code I'm using:
<?php
drupal_add_js('http://example.com/example.js', 'module','footer',FALSE,FALSE,FALSE);
?>
Related
I have created custom page in wordpress and in the page I have a form where users can upload a banner, and input some text.
The code is working perfectly on a local server. The problem is when I transfer to the live page, it is displayed as text instead of working normally.
I have tried to search for the page in cPanel but have later realized the pages are not stored as normal pages but stored in a database.
Please help me how to make my form work.
You can't put a php code (this is a code not a content) as a post content from the admin panel. A php file must be created (or using the functions.php) to serve that page and put the code there.
Find and open the functions.php file. It is located under the wp-content/themes/yourthemename/ folder.
At the end of the file (but before the ?> symbols if exist) add this code
function custom_function_for_your_page() {
// put your php code here
}
add_shortcode( 'custom_functionality', 'custom_function_for_your_page' );
Now as you guess, you can put the php code right below this line // put your php code here.
This is a shortcode. Now you can put that shortcode into the page content.
Open that page from the admin panel, where you've tried to put the php code. Instead of that code put this [custom_functionality].
Good luck :) Tell me if it doesn't work, we'll try more.
Looks like you may need a plugin, here is one such plugin I know about:
https://wordpress.org/plugins/insert-php/
I'm running a wordpress theme that gets updated regularly. I have made some extensive modifications to it. Whats the best way to add all custom code to it at once?
My idea is to put all my code in just 1 file. Accordingly to the page, it would fetch the necessary code from that file.
Is there something I can do instead of add
<?php require("") ?>
for every page that I had modified?
You may insert your code in one of the static elements like Header or Footer sections,require is perfectly normal, just please use require_once function. http://md1.php.net/manual/en/function.require-once.php
Hope it helps you.
I recently purchased a script that I'm trying to change the CSS to pimp it up :)
However since I'm fairly new to CSS/PHP (I've done ASP before), I'm trying to use the "Live view" feature Dreamweaver 5.5 to edit the tpl.php files. I have setup the site as instructed in DW and it's working with basic PHP files, however when I try to open a tpl.php file it doesnt seem to handle all the includes or something, so essentially it doesnt know how to retrieve all the related CSS etc in order to show me what the site looks like.
It has the following code structure:
www.xyz.com -> this calls the index.php
Within index.php, it calls include_once ('global_mainpage.php');
Within global_mainpage.php it then calls $template_output .= $template->process('mainpage.tpl.php');
mainpage.tpl.php is the file that I need to change the layouts/CSS class reference etc.
My ideal way to work with the site is:
Say if I want to change something on index.php
I just click on one of the elements in live view
It would automatically launch the tpl.php file being used
I can then examine the CSS used and make a change to it
hit save and be able to view the change I just made
If this is not possible, do I have no choice but to use Aptana? I've used it before editing PHP code, but not tpl.php - I was hoping to have a WYSIWYG editor for tpl.php...
Many thanks for your help gurus! :)
Why don't you use FireBug on Firefox and hook it up with cssUpdater?
I am new to SMF.
I just installed SMF on my website. I tried editing the index.template.php . After saving changes, it displays raw HTML and PHP on the browser. I tried fixing the prob by returning the the page back to the original state to no avail.
At the moment, everything is gibberish both frontend and backend.
Pls what do i do?
There should be at least an open tag at the top of the file (at the top of every .php file). Make sure you didn't remove this tag. Everything outside of a <?php is interpreted as normal text so if you have removed this it would explain your issue.
Also, being an ex-team member for SMF I can assure you its better to create a copy of the default theme, then make your edits to that theme. Then if you experience an error you can always pass a param in the url to reset to the default theme (in case you need to get into the admin area). To do so end the url with index.php?theme=1
I am very new to WordPress, so I would appreciate some help.
I am using WordPress as a CMS, and I am trying to make the thing work so that when I select a page to edit, there is a special box where I can input PHP code that will execute on my page.
I have found the PHP exec plugin, which works perfectly, but I would like to keep the code out of my main text editor, out of the way of my client's careless fingers.
Any suggestions would be very, very appreciated. Thanks!
You could create a template for each one, and include your PHP there.
Simply select the template from the page edit page.
But if you are only including a little PHP per page, you could get the slug via WordPress in your page template and act on it accordingly.
You can also add an extra meta box on the post editor page, only visible to you, with a textarea where you can add the code. You would save it as a meta field of the post. Your template can check for the existence of this field, and execute it if found.
PHP Exec is the best plugin I have found, and I looked long and hard for that one. The problem with doing it as you suggest is that if the PHP code displays an item on the page, it still has to be formatted within the page as well. It is a simple logistical problem, but somewhat of a complex coding problem. I haven't been able to get around to working on creating a better plugin for it.