• Resolved cathlaura

    (@cathlaura)


    Hi, I’m editing my search.php file and I’d like to display as part of the search results the URL of each result since our site hierarchy is a little crazy but would be informative for our users. But I’d like it to just print
    “/resources/library/kids” instead of “https://www.mydomain.org/resources/library/kids”.

    I saw someone else use str_replace on get_permalink for their issue, so I guess I should be trying to change the permalink string somehow – I don’t know PHP but I sure can copy and paste. This will only be my own site search, so the part I want to remove will always be the same thing, same length…if that helps.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try doing following

    // specify id if you are using outside post loop
    // otherwise keep it as get_permalink()
    $permalink = get_permalink( $id );
    
    // printing output
    echo str_replace( get_bloginfo( 'url' ) . '/' , '', $permalink );

    See if this helps!

    Thread Starter cathlaura

    (@cathlaura)

    Cool. A friend commended your solution as elegant. I played with what you gave me a bit a finally settled on this:

    Posted in <?php // printing output
    echo str_replace( get_bloginfo( 'url' ) , '...', get_permalink( ) );
    ?>

    Thanks a bunch.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_permalink to output just the path?’ is closed to new replies.