<?php bloginfo('stylesheet_directory'); // Theme path ?>
All posts by Pramod T P
Remove spaces from the beginning and end of a string – PHP
<?php echo trim(" Test "); // Test //Will remove the spaces from the beginning and end ?>
Function that displays the categories – WordPress
<?php wp_list_categories(); // List all categories ?>
How to read all the keys or a subset of the keys of an array – PHP
<?php $testArray = array(1 => 5, "name" => "First Name"); print_r(array_keys($testArray)); //Array ( [0] => 1 [1] => name ) ?>
Check whether a variable is empty – PHP
<?php // Example 1 $string=""; if(empty($string)) echo "Empty string"; else echo "Not an empty string"; //Empty string ?> <?php // Example 2 $strng="Test"; if(empty($strng)) echo "Empty string"; else echo "Not an empty string"; //Not an empty string ?>
Add backslashes in front of special characters – PHP
<?php $str = "Test's"; echo addslashes($str); //Test's ?>
Removes backslashes – PHP
<?php $str = "Test's"; echo stripslashes($str); //Test's ?>
Converts characters to HTML entities – PHP
<?php $str = "<p>First Name</p>"; echo htmlentities($str); //<p>First Name</p> ?>
Randomizes the order of the elements in an array – PHP
$numbers = range(0, 9); shuffle($numbers); foreach ($numbers as $number) { echo $number; }
Create an array containing a range of elements – PHP
<?php $numbers = range(0, 9); foreach($numbers as $value) echo $value." "; //Will output 0 1 2 3 4 5 6 7 8 9 ?>