$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>footer - Use custom field value as href|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

footer - Use custom field value as href

matteradmin9PV0评论

I created a custom field and would like to use its value as the href on a tag that would go on my footer.

The custom field is on the Settings > General area of the dashboard and I used add_settings_field() in order to create it.

So, for example, the value inserted in my custom field is "" and I would like that in my href. It would basically look like this:

<a href="CUSTOM FIELD VALUE GOES HERE">Click Here</a>

Is there any way to accomplish that?

I created a custom field and would like to use its value as the href on a tag that would go on my footer.

The custom field is on the Settings > General area of the dashboard and I used add_settings_field() in order to create it.

So, for example, the value inserted in my custom field is "https://www.google" and I would like that in my href. It would basically look like this:

<a href="CUSTOM FIELD VALUE GOES HERE">Click Here</a>

Is there any way to accomplish that?

Share Improve this question edited Feb 6, 2019 at 22:11 lulufv asked Feb 6, 2019 at 14:36 lulufvlulufv 51 silver badge3 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default -1

To retrieve a value after using add_settings_field() you should use get_option().

So you could do something like this...

$value = esc_html(get_option('option_name'));

if ($value) {
    echo '<a href="' . $value . '">Click Here</a>';
}

You just need to change option_name to your field name. The code will grab the value and if it isn't false echo the link. Also added the escaping.

*Updated after OP gave more details

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far