• I am currently working on a plugin that is loading a template to print a loop of query results. The template populates some html tags with data from the query like this:

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="entry-header">
    	    <h3 class="entry-title title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        </div>
        <div class="entry-content">
    	<?PHP if(subtitle()): ?>
        	<div class="subtitle"><?PHP print subtitle(); ?></div>
    	<?PHP endif; ?>
        </div>
    </article>

    For this to work I have setup a custom function (subtitle()) that returns the subtitle. This works fine.

    Now I’m also using the value from subtitle() elsewhere in the plugin and was wondering if it is bad practice to always call that custom function instead of passing variables around.

    I could instead also pass variables to the template – but I found it more convenient for the designer to see functions similar to wp-functions like “the_title()”. I hope my question is not too cryptic? Thank you!

  • The topic ‘variables vs functions in a plugin template’ is closed to new replies.