Skip Navigation

[Resolved] Question about modifying field content

This support ticket is created 2 years, 6 months ago. 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 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by saulB-3 2 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2194289

Hi there,

I have a custom field that stores a URL. The content in the field might be "hidden link."

When displayed on a webpage, it displays the same content for both the link target text and the href attribute value:

target text: hidden link
href attribute value: hidden link

What I would like to do is manipulate the link target text and strip out "hidden link" so only the domain appears:

target text: hidden link
href attribute value: hidden link

Is there a filter I can hook into to make this happen? Or should I write a custom shortcode? What's the best way to accomplish this?

Thank you!

Saul

#2194551

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Saul,

Thank you for contacting us and I'd be happy to assist.

There is no built-in filter available for this, so you can use a custom shortcode for creating a link in this format.

For example:


add_shortcode('get-filtered-url', 'get_filtered_url_func');
function get_filtered_url_func($atts) {

	$a = shortcode_atts( array(
		'field' => '',
	), $atts );

	$url_field_value = types_render_field($a['field'], array("output" => "raw"));

	if(!empty($url_field_value)) {
		$url_field_value_arr = explode('://', $url_field_value);
		$link_text_URL = rtrim($url_field_value_arr[1],"/");
		$content = '<a href="'.$url_field_value.'">'.$link_text_URL.'</a>';

		return $content;
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After that, you'll be able to use this shortcode in your content like this:


[get-filtered-url field="book-url"]

You'll replace the "book-url" field slug with your website's URL custom field.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2195253

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.