Skip Navigation

[Resolved] Turning dashes into spaces

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem:
Replace the dash character with space in text outputted from other shortcode, for example:

wpv-search-term

Solution:
I suggest you try to create another shortcode to achieve what you want, for example,
1) add below codes into your theme/functions.php:

add_shortcode('dash2space', 'dash2space_func');
function dash2space_func($atts, $content){
    $content = do_shortcode($content);
    $content = str_replace('-', ' ', $content);
    return $content;
}

2) Use above shortcode [dash2space], like this:

[dash2space] ...wpv-search-term param="type"... [/dash2space]

Relevant Documentation:
http://php.net/manual/en/function.str-replace.php
https://codex.wordpress.org/Function_Reference/add_shortcode

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 7 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#561615

I am trying to change the headline on my landing page based on my URL. This url

example.com/?type=dancers

Should make this headline: "Legal Advice for Dancers"

And if there's nothing there, it should make this headline: "Legal Advice for Artists"

I wrote this and it works well:

[wpv-conditional if="( '[wpv-search-term param="type"]' eq '' )"]Artists[/wpv-conditional][wpv-search-term param="type"]

Except....when I need two words in my landing page headline. Unfortunately:

example.com/?type=break-dancers

produces:

Lawyers for break-dancers

Is there some way to turn the dashes into spaces?

#561837

Dear Hashim,

It is expected result, since in the URL you mentioned above:
example.com/?type=break-dancers
The value of URL parameter "type" is "break-dancers", this is a string with "dash", and Views shortcode [wpv-search-term] does output the string value "break-dancers" correctly, there isn't such a feature within shortcode [wpv-search-term] can achieve what you want:
Turning dashes into spaces

See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term
This shortcode displays the search term when visiting the search results page,

In your case, I suggest you try to create another shortcode to achieve what you want, for example,
1) add below codes into your theme/functions.php:

add_shortcode('dash2space', 'dash2space_func');
function dash2space_func($atts, $content){
	$content = do_shortcode($content);
	$content = str_replace('-', ' ', $content);
	return $content;
}

2) Use above shortcode [dash2space], like this:
[dash2space] [wpv-search-term param="type"] [/dash2space]

More help:
hidden link
https://codex.wordpress.org/Function_Reference/add_shortcode

#562177

Wow, today's amazing. Luo, you fast exceeded the response I hoped for.

I learned a lot just by following what you did here

#562215

You are welcome

The forum ‘Types Community Support’ is closed to new topics and replies.