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.
Related
So I'm working on a wordpress theme and it's really twisted. The problem is I'm comfortable just with html and css, as I'm a code noob, so I would really appreciate your help here.
The problem here is that I want to put a tracking script and a redirect on a specific button. I'd now how to do this if I'd find the button's html form.
But when I go to the code in the page where the button is, this is the only thing showing regarding the button
<?php BookYourTravel_Theme_Utils::render_submit_button("primary-btn",
"submit-accommodation-booking", esc_html__('TRIMITE REZERVAREA',
'bookyourtravel')); ?>
BookYourTravel is the theme
I know you should maybe see all the files to know what to do, as this doesn't seem as enough info.
But I also have a functions.php file. Should I look there? Do you have any idea where should I go?
Thank you a lot. Really stuck here.
Are you writing the theme yourself or are you working with someone else's theme? If you're working on someone else's theme, I would reccommend looking into building a child theme so if you change some code, the OG theme is still there in it's entirety and if they update the theme, your code wont get destroyed in the update. There are tons of tutorials on how to set up a child theme and theres a plugin that will make it for you called Child Theme Configurator if you're not too keen on doing it yourself.
You should be super careful when you're editing functions in your theme(especially if you're new to PHP), but that's where this html is being generated. One of those functions is the thing that's generating your html. If you find where the function is held, you could probably change it so it echos the extra code you're looking to implement but it would be on every button that this function generates throughout your site.
You didn't really give enough information for us to do anything. So if you are really pulling your hair on this one just replace the old button with a new button that you wrote. I can help you out on that end if you don't know javascript.
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);
?>
I've used a modified themeforest template for a single php page and have an issue where the navigation links that take you to the various unique id's on the page are working fine but cut off the top part of the section h3 that it has linked to.
It's a positioning problem for sure and most likely to do with the modifications I made to the flex-slider that the template included.
But I can't determine how to adjust the css (or script) to correct the issue.
For example, the site is http://goudkamp.stacklaw.com.au/ and when you click Services, you can see what I mean.
I have the template on the site as well so you can see how it SHOULD work - http://goudkamp.stacklaw.com.au/v2/template/.
I came across another article that suggested using the script
if(window.location.hash.length){
$(window).scrollTop($(window).scrollTop() - 100);
}
However, I don't think I should need it when the template works perfectly.
I just don't know where to start looking to make the necessary adjustments.
Please help!
Thanks in advance
Wait - I found it!
After looking at the suggestion on the other article, it made me think that it must be done in the theme's custom scripts. So I looked in the custom.js file for any script that referenced the main nav.
There was an "offset" line with the markup "//use this to position the window exactly where you want". Testing a small change to this had the desired effect.
Thanks anyway.
I cannot find a category specific calendar, or any sample code to allow me to get slightly dirty... Anyone know of a category specific calendar so I can call it for example:
get_calendar(true, true, $cat_id);
Otherwise I will have to copy the get_calendar function and make my own get post by category loops sigh
Ended up making my own calendar.
This is a really shaky way of doing it but it works great.
Create a new page in your template directory called “the-calendar.php” place the following code in it: http://pastebin.com/sUSzJMWM
Create a new script file (that has access to jquery).
Put the following code in it
(MAKE SURE YOU HAVE SET site_url to equal “get_template(‘blog_info’) . ‘/’”): http://pastebin.com/Q16ibAZ0
Now just include this wherever you want the calendar to be (keeping in mind that the above script must be accessible):
http://pastebin.com/fyhXrCiW
Don’t forget to style your date.php page in your wordpress theme directory!!!
Here is some default styling that looks awful but should get you started:
http://pastebin.com/NMauFJWq
The Calendar works by calling (via AJAX) an external PHP file that gathers and echos the HTML code that generates the table. On the success of the AJAX, it just fills the specific div with the returning html.
Please feel free to expand on the code and also ask questions if you can’t get it to work! I hope it saves you some time!
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.