Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:19:30+00:00 2026-06-07T13:19:30+00:00

I am trying to turn a standard wordpress title into a slug, that makes

  • 0

I am trying to turn a standard wordpress title into a slug, that makes all characters lowercase, replaces spaces with dashes, and removes all “&” symbols that are in the titles.

So lets use this title as an example: “Identity & Wayfinding“

Here is my PHP:

<?php 
$title = get_the_title(); 
$lower = strtolower($title);
$noDash = str_replace(' ', '-', $lower);
$noAnd = str_replace('&', '', $noDash);
echo $noAnd;
?>

This turns my title into “identity-#038;-wayfinding“

The lowercase conversion worked, but the replacing of the”&” with nothing isnot working . It is converting the “&” into an HTML special character. Any idea how I can simply replace the “&” with a blank, but also REMOVE the dash after that so the final title would be: “identity-wayfinding”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:19:32+00:00Added an answer on June 7, 2026 at 1:19 pm

    If you want a slug, there are plenty of utilities which will do it for you, but neither htmlentities or urlencode is correct. Doctrine 1.2 included a urlizer class with a set of static functions including urilize which will accomplish the behavior you desire in a more robust manner (handles UTF-8 and unaccenting correctly, etc.)

    It can be found here

    If you want something less robust but far simpler:

    function slugify($sluggable)
    {
        $sluggable = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $sluggable);
        $sluggable = trim($sluggable, '-');
        if( function_exists('mb_strtolower') ) { 
            $sluggable = mb_strtolower( $sluggable );
        } else { 
            $sluggable = strtolower( $sluggable );
        }
        $sluggable = preg_replace("/[\/_|+ -]+/", '-', $sluggable);
    
        return $sluggable;
    }
    

    That’ll strip non-alphanumeric characters (but also accented characters) and make spaces, + signs, and hyphens into hyphens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a procedure in SQL that I am trying to turn into Linq:
Trying to turn this: href=/wp-content/themes/tray/img/celebrity_photos/photo.jpg into: href=/img/celebrity_photos/photo.jpg So I'm simply trying to remove /wp-content/themes/tray/
I am trying to turn off Request Validation for all action methods in a
I am trying to turn specific words or phrases into links with jQuery. So
I am trying to turn div#sidebar into a sidebar in my app. My code
Stack: I'm trying to turn my website's user profile into more of a feed
I am trying to quickly invert the colors of an existing UIView (turn into
Having trouble trying to turn an XDocument into an list of objects, in particular
I am trying to turn a mock-up into a page with css but I'm
I am trying to turn the the flash page flip (source: http://76design.com/shiftcontrol/index.php/2005/07/03/dynamic-page-flip/ ) into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.