Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Alessandro Muraro
Alessandro Muraro
15,457 Points

Retrieve options set from a plugin

Hi there, I am creating my own simple plugin loosely following the Treehouse tuts. I need to print the options I saved in my plugin (as text).

I can retrieve the values saved in my plugin option like this:

<?php $options = get_option('wpglobalsettings'); ?> <?php echo $options['wpglobalsettings_image1']; ?>

but what i really want is to avoid calling the get_option on each page I need my plugin settings to be shown.

I tried to do this:

function wp_global_settings_frontend(){ $options = get_option( 'wpglobalsettings' ); }

add_action('wp_head', 'wp_global_settings_frontend');

but when I print to screen the $option array, it's empty. What am I doing wrong? Many thanks!

1 Answer

Mike Costa
PLUS
Mike Costa
Courses Plus Student 26,362 Points

I'm not too familiar with the wordpress plugins but maybe try:

function wp_global_settings_frontend(){ 
return get_option( 'wpglobalsettings' );
 }