-
AuthorPosts
-
November 14, 2017 at 11:30 pm #876852
Dear
How do I add a custom PHP script in the header?
It shows the opening days / hours of the store when the site is open.
For example: if you visit the website on monday, the website shows: Monday: 9AM – 5PM
If you visit the website on Wednesday, the website shows: Wednesday: closed.I have the script and it works, cause I’m currently running it on my HTML website.
Just need to figure out to add in the header on this wordpress template.Thanks in advance!
November 14, 2017 at 11:49 pm #876863Hey Boeckske23,
If you go to appearance > editor > header.php , you should be able to add your script before the closing head tag.
Best regards,
Jordan ShannonNovember 15, 2017 at 9:32 pm #877216So, I did what you said but for some reason he is not showing it in the correct place.
Example:
What did I do?
1) add my php script to header.php before the closing head tag.
2) added the call for the php script in my secondary headerExample:
But as you can see, the output result is correct but the place needs to move next to the phone number.
November 15, 2017 at 10:49 pm #877244Hi,
Please provide a link to the site in question.
Best regards,
Jordan ShannonNovember 15, 2017 at 11:49 pm #877262This reply has been marked as private.November 15, 2017 at 11:59 pm #877266Hi,
If possible, add the admin info in the private area so we can login and investigate further.
Best regards,
Jordan ShannonNovember 16, 2017 at 12:04 am #877268This reply has been marked as private.November 16, 2017 at 4:25 pm #877601How is the investigation going?
November 16, 2017 at 9:01 pm #877736Hi Boeckske23,
Try wrapping it in a span with some class. And that file should have somehting like this
ob_start(); $yourcode = ob_get_contents(); ob_end_clean(); return $yourcode;
Can you show us the code from that file?
Best regards,
Victoria- This reply was modified 7 years ago by Victoria.
November 16, 2017 at 11:46 pm #877845<?php $vandaag = date("l"); switch($vandaag) { case 'Monday': echo 'Maandag: 14u - 19u'; break; case 'Tuesday': echo 'Dinsdag: 14u - 19u'; break; case 'Wednesday': echo 'Woensdag: : 14u - 19u'; break; case 'Thursday': echo 'Donderdag: 14u - 19u'; break; case 'Friday': echo 'Vrijdag: : 14u - 19u'; break; case 'Saturday': echo 'Zaterdag: 9u - 17u'; break; case 'Sunday': echo 'Zondag: gesloten'; break; } ?>
And I put this into the header:
<? require_once(ABSPATH. ‘/wp-content/openingsuren.php’); ?>
- This reply was modified 7 years ago by Boeckske23.
November 17, 2017 at 10:29 am #877998Hi Boeckske23,
Try wrapping it in a span with some class. And that file should have somehting like this
ob_start();
$yourcode = ob_get_contents();
ob_end_clean();
return $yourcode;
Can you show us the code from that file?
Best regards,
VictoriaI don’t understand your example
November 17, 2017 at 3:04 pm #878091Hi,
Please simply follow this:
To add code to your header, use this code snippet:
/* Describe what the code snippet does so you can remember later on */ add_action('wp_head', 'your_function_name'); function your_function_name(){ ?> PASTE HEADER CODE HERE <?php };
Once you have the relevant code snippet(s) ready, you need to add them to the functions.php file of your child theme. You can either edit this file by connecting to your site via FTP. Or, you can go to Appearance → Editor and select the functions.php file. Then, paste your code at the end of the file:
Best regards,
Jordan ShannonNovember 17, 2017 at 4:01 pm #878136This is the code snippet, adjusted to what you gave me:
/* Openingsuren tonen in header */ add_action('wp_head', 'openingsuren'); function openingsuren(){ ?> $vandaag = date("l"); switch($vandaag) { case 'Monday': echo 'Maandag: 14u - 19u'; break; case 'Tuesday': echo 'Dinsdag: 14u - 19u'; break; case 'Wednesday': echo 'Woensdag: : 14u - 19u'; break; case 'Thursday': echo 'Donderdag: 14u - 19u'; break; case 'Friday': echo 'Vrijdag: : 14u - 19u'; break; case 'Saturday': echo 'Zaterdag: 9u - 17u'; break; case 'Sunday': echo 'Zondag: gesloten'; break; } <?php };
But I get a HTTP error 5000 then.
But actually what I need to know is how to refer to the PHP script in the header location that I marked above.
The result of the script needs to be shown in the ‘Phone Number or small info text’ field, see image below.
How do I call the php script for the result to be shown there.
If you can tell me this, I think thats all I need to know.November 17, 2017 at 6:35 pm #878235Hi Boeckske23,
You echo right away and it shows the text before html, instead of rendering it with the page.
It is better to add your working hours variable in the file below but copy that file to the child theme while preserving the folder structure.
/enfold/includes/helper-main-menu.phpBest regards,
VictoriaNovember 19, 2017 at 9:13 pm #878847Thank you!
I got it working!Thank you for pointing me in the right direction!
November 20, 2017 at 10:35 am #879015Hi,
Great, glad you got it working :-)
Please let us know if you should need any further help on the topic or if we can close it.
Best regards,
RikardNovember 20, 2017 at 5:01 pm #879223you may close it!
November 20, 2017 at 5:11 pm #879232Hi,
If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Custom PHP script in header’ is closed to new replies.