Answer the question
In order to leave comments, you need to log in
How to display a link from the settings to the template in WordPress correctly?
Hey! tell me I made links to social networks in the site settings ... Ie. in the admin area, let's say a link to the VKontakte group is put and displayed in the template through the function - echo get_option('url_vk'); Everything is fine if you add the full address https://vk.com/gruppa in the settings , then everything is displayed as it should, and if you specify the link in the settings simply without a protocol (vk.com/gruppa), then the path relative to the domain is displayed, then there is so... domain.ru/vk.com/gruppa .. How can I get the correct address displayed in both cases?
Answer the question
In order to leave comments, you need to log in
Option 1: Validate the field on the settings page, accept only a single format (with or without https:// - not so important).
Option 2: Check string before output, append log if missing:
$url = get_option( 'url_vk' );
if ( false === strpos( $url, 'https://' ) ) {
$url = 'https://' . $url;
}
echo esc_url( $url );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question