• Hello, I’m very new to PHP and am having some small troubles….
    I have a code for displaying a table which is inserted in many places of my blog and would like to place this code into the functions.php so that every time I only need to enter the table contents as variables and the layout would be stored centrally (less management chaos) in the functions.php file.

    The code, in pure html, would look like this:

    <div style="width=100%">
    	<div>
    	<a href="http://www.ABC.com/A.jpg"><img src="http://www.ABC.com/A.jpg"/></a>
    	</div>
    
    	<div>
    	This will be the place for content
    	</div>
    </div>

    And I have come up currently with the following code:

    ====For the PHP part (Functions.php)=====

    function customized_table{
    echo "	<div style="width=100%">
    		<div>
    		<a href=" echo $img_url;"><img src="echo $img_url;"/></a>
    		</div>
    
    		<div>
    		$my_content;
    		</div>
    	</div>";
    }

    ====For the HTML part=====

    <?php
    $img_url = "http://www.ABC.com/A.jpg";
    $my_content = "This is the content";
    customized_table;
    ?>

    And this crashes up the website. I assume this comes from function.php automatically starting this function in functions.php. I want this function to only be executed when I call out for an execution. Can someone please give me some hints of how to achieve this and whether what I’m doing is a good practice or not? (I’m doing this in the functions.php in a child theme, so aside from that…)

    Thank you so much!

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Placing a frequently used code in function.php and recalling in html – how?’ is closed to new replies.