0

If I call

curl -I https://example.com

In terminal I get the correct response

Link: <https://example.com/wp-json/>; rel="https://api.w.org/"

If I call

$response = wp_remote_head( 'https://example.com' );

The I print_r the response. The Link: I get is

Link: ; rel="https://api.w.org/"
Link: ; rel=shortlink

There seems to be the href stripped out of the data, but the semi-colon has been left. This is the reccomemded way from wordpress to assert if REST api is active and if pretty permalinks are selected.

What is the correct way to get the href link from the from a page header?

0

Turns out it was there all along, but being rendered into an html tag during the output. I ended up using;

echo htmlspecialchars($response);

To get this to be displayed correctly on the page. Although I want to be checking against it in php, which I haven't go to figuring out yet, it is nice to have found it working correctly. It was displayed in the html in the element inspector which I hadn't thought to check ....whooops.

  • Checking against the string of this works exactly as normal string checking in an IF statement, so this isnt a problem, just the rendering was a little unusual in html. – fullmoonfriday Dec 6 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.