Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #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!

    #876863

    Hey 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 Shannon

    #877216

    So, I did what you said but for some reason he is not showing it in the correct place.

    Example: header

    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 header

    Example:

    But as you can see, the output result is correct but the place needs to move next to the phone number.

    #877244

    Hi,

    Please provide a link to the site in question.

    Best regards,
    Jordan Shannon

    #877262
    This reply has been marked as private.
    #877266

    Hi,

    If possible, add the admin info in the private area so we can login and investigate further.

    Best regards,
    Jordan Shannon

    #877268
    This reply has been marked as private.
    #877601

    How is the investigation going?

    #877736

    Hi 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.
    #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.
    #877998

    Hi 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

    I don’t understand your example

    #878091

    Hi,

    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:

    Add code to functions.php file

    Best regards,
    Jordan Shannon

    #878136

    This 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.

    #878235

    Hi 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.
    Image 2017-11-17 at 18.31.20.png
    /enfold/includes/helper-main-menu.php

    Best regards,
    Victoria

    #878847

    Thank you!
    I got it working!

    Thank you for pointing me in the right direction!

    #879015

    Hi,

    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,
    Rikard

    #879223

    you may close it!

    #879232

    Hi,

    If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 18 posts - 1 through 18 (of 18 total)
  • The topic ‘Custom PHP script in header’ is closed to new replies.