I have the following URL: http://test.com/client/!MG2s-/

I want to be able to grab the slug and use it further down in my code

With the following code:

$page_slug=$post->post_name;
echo $page_slug;

the output is !mg2s

Even if the url is http://test.com/client/%21MG2s%2D/ the result is still the same. The slug is generated from a third party app, so the hyphen is required. I understand that dashes are used to sanitize titles, but I need to find a way to display the hyphen.

I have also tried with no success:

$page_slug= urlencode($post->post_name);
$str = str_replace('-', '%2D', $page_slug);
echo $str;

Is there any way that the hyphen can be displayed?

Read more here: Encode the url including hyphen in php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: