Skip to:
Content
Pages
Categories
Search
Top
Bottom

Creating a slug from a string or title for part of link url

  • @gingram815

    Member

    I am trying to create a link in the membership directory under each person’s name.
    You can see what I have so far at http://transylvaniawellnessalliance.com/members/.

    I did this by putting this code into the members-loop.php file.
    `

    `

    This grabs the name of the member’s profession from their profile data and uses is to create a link to a page that describes that profession. This works great except for one small problem:

    When the profession has 2 names such as “Naturopathic Doctor,” I need to turn this into a slug so that the link works. I have tried using the “sanitize_title_with_dashes()” function but it kept returning empty or doing nothing.

    How can I get the “Naturopathic Doctor” to read “naturopathic-doctor” inside the link?

    Thank you for any help,
    Glenn

Viewing 3 replies - 1 through 3 (of 3 total)
  • @djpaul

    Keymaster

    sanitize_title_with_dashes() should work. This might be a stupid question, but can you show how you were trying it? Thanks.

    @gingram815

    Member

    That is likely the problem. I’m not a coder.
    I have tried a variety of markups. Here is an example:
    `

    `
    This returns the link unsanitized (ex: http://transylvaniawellnessalliance.com/wellness-businesses/Naturopathic Doctor).

    @gingram815

    Member

    Okay, I figured out how to do it using another post of yours:
    `<?php
    function member_loop_profession_link(){
    $data = bp_get_member_profile_data( ‘field=Profession’ );
    if ( $data ){
    $sandata = sanitize_title_with_dashes($data);
    echo “

    “;
    }
    }
    add_action( ‘bp_directory_members_item’, ‘member_loop_profession_link’ );

    ?>`
    This is placed in functions.php.
    It works like a charm; thank you so much.

    Glenn

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a slug from a string or title for part of link url’ is closed to new replies.
Skip to toolbar