str_replace using the_permalink()

Trying to use str_replace to remove a directory from the_permalink() in WordPress:

$the_old_link = the_permalink();
$the_new_link = str_replace('/unwanted_folder', '', $the_old_link);

Related posts

Leave a Reply

2 comments

  1. yes, you need to use get_permalink(). This is used to save the permalink in a variable

    your codes would see something like this

    $the_old_link = get_permalink();

    $the_new_link = str_replace( '/unwanted_folder', '', $the_old_link );

    then where you want to use the new link just echo it.

    an instance can be <a href="<?php echo $the_new_link; ?>" class"new-link">link</a>