Apparently global does the trick. The problem was that my variable $categories should have been redefined with a global in front of it, in each template I needed to use it. More Solution cms - How do I represent 'chunks' of content within Wordpress? in WordPress comments - What tools are available for managing/writing to WordPress? in WordPress css - Customizing a WordPress theme without changing it? in WordPress plugins - Tips for using WordPress as a CMS? in WordPress How to start learning CSS and theme development? in WordPress Reffered: https://wordpress.org/