最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How To Display Value from Theme Options Field in Front End Template?

programmeradmin2浏览0评论

I put this code into my functions.php and it work nice.

Now I want to display value from Sample Select Options filed in some front-end templates.

How can I do that? I tried get_option

<?php echo get_option( 'sample_select_options', true); ?>

but it return number 1 no matter what is selected.

I put this code into my functions.php https://gist.github/corvannoorloos/4703066 and it work nice.

Now I want to display value from Sample Select Options filed in some front-end templates.

How can I do that? I tried get_option

<?php echo get_option( 'sample_select_options', true); ?>

but it return number 1 no matter what is selected.

Share Improve this question asked Jan 7, 2014 at 13:12 pendjerpendjer 1283 silver badges11 bronze badges 2
  • At first glance, you need to make sure you call the correct option. Looking at the Gist, there is a _s_ prefix to the option. Since _s_simple_select_options is an array, you might need a foreach loop to deal with multiple values. – JMB Commented Jan 7, 2014 at 13:37
  • Hi @Strap1. Thank you for the advice. I am not related to php so I am trapped here. I found this post aquoid/news/tutorials/wordpress-theme-options/… There is a code snippet to retrive the options. Is that near to what I need? – pendjer Commented Jan 15, 2014 at 18:30
Add a comment  | 

2 Answers 2

Reset to default 1

I think you need to display it like this:

<?php $options = get_option( 'your_registered_option' ); echo $options['sample_select_options']; ?>

Replace your_registered_option with the name you gave in functions php for register_setting();

Hope this helps

This is what worked for me (March 2020).

In the PHP of your front end page, add:

settings_fields("my_settings_group");

Note that "my_settings_group" should be replaced with the name you gave the option group in your "register_setting()" function on the backend.

Then when you want to display an option from that settings group, use this code in your HTML:

<?php echo esc_attr(get_option("my_option_01")); ?>

Replacing "my_option_01" with the actual name of the option you want to insert.

发布评论

评论列表(0)

  1. 暂无评论