Skip Navigation

[Resolved] Question about modifying field content

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.

Our next available supporter will start replying to tickets in about 5.04 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by saulB-3 1 month, 3 weeks ago.

Assigned support staff: 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!