Passer la navigation

[Résolu] Hiding http:// or https:// from URL field label

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

We have a URL field that we are displaying on a template as a URL link.

The link would still point to the full URL but the label display should remove the http:// . Is that possible?

Solution:

You might consider custom codes, for example:

https://toolset.com/forums/topic/hiding-http-or-https-from-url-field-label/#post-2277275

Relevant Documentation:

This support ticket is created Il y a 4 years, 4 months. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Fuseau horaire du supporter : Asia/Hong_Kong (GMT+08:00)

Ce sujet contient 9 réponses, a 2 voix.

Dernière mise à jour par melodyM Il y a 4 years, 4 months.

Assisté par: Luo Yang.

Auteur
Publications
#2276911

We have a URL field that we are displaying on a template as a URL link. The output from this field is currently

lien caché

Is there any way to modify the label here to display as

lien caché

The link would still point to the full URL but the label display should remove the http:// . Is that possible?

#2276933

lien caché was intended for the second one. I think your filter added the http://

#2276935

Yeah it did it again. We just want the part starting with www to display.

#2277275

Hello,

There isn't such kind of built-in feature, according to URL definition, the "scheme" is required:
lien caché

You might consider custom codes, for example, create a custom shortcodes to remove scheme from link label, like this:
1) Add below PHP codes into your the Toolset custom codes snippet:

add_shortcode('my-url', function($atts, $content){
	$field = 'wpcf-' . 'my-url'; // replace my-url with your custom URL field slug
	$value = get_post_meta(get_the_ID(), $field, true);
	$label = preg_replace( "#^[^:/.]*[:/]+#i", "", $value );
	$res = '';
	if($value){
		$res = sprintf('<em><u>lien caché</u></em>', $value, $label);
	}
	return $res;
});

https://toolset.com/documentation/programmer-reference/adding-custom-code/

Please replace "my-url" with your custom URL field slug

2) use above shortcode like this:
[my-url]

#2277315

I think I did it right. I added the code to the custom code section in settings. I changed "my-url" to "website" everywhere it appeared, which is the slug for the website URL field. I added a new block with the shortcode [website] to the bottom of the template. But when I reload the page, it is only showing the shortcode, not executing it. You can see that here:

lien caché

I can provide access to the admin area if necessary.

#2277321

Please provide your website credentials in below private message box, thanks

#2277583

Please use the Shortcode block at the end of the template to apply what you will do here. Or replace the Shortcode block with however you have to do it. Please leave the existing Website field displaying with the http:// present.

#2278171

It should be a cache problem, I have done below modifications in your website:
1) Dashboard, click "Delete Cache" button
2) Dashboard-> Toolset-> Settings-> Custom codes, activate the item "remove-http-website-link",

Please test again, check if it is fixed.

#2280957

That's working. Thanks hugely! Great work.

#2281027

My issue is resolved now. Thank you!