Adding php within a return statement [closed]

You can just call PHP functions directly. In this case however we possibly don’t want to call the_permalink() since it echoes out the link:

function the_permalink( $post = 0 ) {
    /* ... */
    echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) );
}

whereas we want to return the link in a string. So your options are:

  1. do use the_permalink(), but capture the output buffer to get the echoed link URL:

    function read_more() {
        ob_start();
        the_permalink();
        $permalink = ob_get_clean();
        return '<a href="' . $permalink . '">Read More</a>';
    }
    
  2. or replicate the filter and escaping from the_permalink in your own code, saving it in a variable to use:

    function read_more() {
        $permalink = esc_url( apply_filters( 'the_permalink', get_permalink(), 0 ) );
        return '<a href="' . $permalink . '">Read More</a>';
    }
    
  3. or just use get_permalink() instead, unfiltered, which is what a lot of WordPress’s own code does (sometimes without escaping too):

    function read_more() {
        return '<a href="' . esc_url( get_permalink() ) . '">Read More</a>';
    }
    

(As an aside, if you were doing this in a plugin or theme you were distributing you’d also want to make ‘Read More’ translatable, e.g. '<a href="' . $permalink . '">' . __( 'Read More' ) . '</a>'; )