footer - Use custom field value as href

admin2025-06-03  2

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748936843a314971.html

最新回复(0)