WordPress define own variable for theme

I am quite familiar with wordpress template tag and working on new theme. I want to make bunch of variables which I will use quite often in my theme. Few are very simple template tag and few my own HTML structure to reuse in other template files.

Fore e.g I want to make variable for the_ttle() or the_permalink like $title = the_title(); or $perma = the_permalink(); so whenever I will add $title or $perma in template file it will echo the title or permalink.

Read More

and for html structure e.g I am defining recent post loop.

$recentloop = <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
get_thumbnail();
the_title();
get_post_meta(); etc.....
<?php endwhile; else: ?>
<?php endif; ?>

Something like above I am not sure if there is anything wrong 🙁

So to make it happen where I should define these variables so I can use it for every template files.

I read this topic http://wordpress.org/support/topic/passing-php-variable-between-template-files#post-1506298 but no idea how and where to place global $variable

I will really appreciate your help.

Related posts

Leave a Reply

1 comment

  1. Not sure if you are still having such problems.

    As the title & permalink will update in every post loop, you shouldn’t make it a variable that is available everywhere. But if you insist to do so, you can put the variable in functions.php.