How to convert any full URL path to relative to WordPress installation (root)

If you want to make a URL relative from the WordPress root, you can use the following WordPress function.

<?php

$full_url = "https://intelyblog.com/how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/";

$relative_to_wordpress = wp_make_link_relative($full_url);

echo $relative_to_wordpress;

?>

Result: /how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/

That’s all! Happy coding!

How to write if else statement in a single line (compact if else statement) using PHP

Normal way of writing an if else statement

<?php

$result = '';

$count = 55;
$target = 70;

if($count >= $target) {
   $result = 'High';
} else {
   $result = 'Low';
}

?>

Now let’s see how the above can be written in a single line.

<?php

$result = '';

$count = 55;
$target = 70;

$result = ($count > $target) ? 'High' : 'Low';

?>

That’s it! Happy coding!