简体   繁体   中英

How to remove prefix from url in PHP/Wordpress

I have a url inside of a <p> tag assigned to a data array. I entered in the following code:

     $link = home_url();




   'side_by_side_content' => [ 
        "img" => [
            "src" => "/wp-content/uploads/2018/02/hello.jpg",
            "alt" => "Hello"
        ],
        "title" => "Hello World",
        "text" => "<p>Sorry! It appears the page you're looking for cannot be found. You can continue on to <a href=\'<?php echo $link; ?>\'>test.com Homepage</a></p>"
    ]

So when I run this code, the url comes up as test.com /<?php echo $link; ?> /<?php echo $link; ?> .It needs to come up on the homepage or just test.com is there something I'm missing here?

You're declaring php inside a php.

simply do this:

'<p>Sorry! It appears the page you\'re looking for cannot be found. You can continue on to <a href="'.$link.'">test.com Homepage</a></p>'
  1. you are using php inside php
  2. a tag was not properly set, just use sth like

    href="'.$link.'">test.com

I actually solved the issue by doing this:

href=".'/'." and also href='$link'

Thanks for all your help guys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM