0

I have an issue. I have a piece of sharing code which I created for social media.

<a href="http://twitter.com/home?status=<?php the_title(); ?>.<?php the_permalink();?>" class="twitter">

Now when I run this through the W3 Validator it says there shouldn't be a space. Now when I looked at the code it was outputting the title DOES have spaces in it.

How do I sanitize this title to add in dashes within my url?

I just want the title to add dashes in this context only. I have looked at the sanitize_title function and the_title_attribute function in the Wordpress Codex but don't really know how to make it work in this situation. I am sure there is a simple solution. Any help would be great.

Dan

0

You can replace the space to dashes using wordpress sanitize_title_with_dashes function Try below code.

 <a href="http://twitter.com/home?status=<?php echo sanitize_title_with_dashes(get_the_title(get_the_ID())); ?>.<?php get_the_permalink(get_the_ID());?>" class="twitter">

I have used get_the_title() and get_the_content() functions because these both function return the context instead of echo them, and i think you are concatenating the string.

Hope this help .

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.