Get current page URL in PHP

<?php echo curPageURL(); ?>


function curPageURL() {
$pageURL = ‘http’;
if ($_SERVER[“HTTPS”] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER[“SERVER_PORT”] != “80”) {
} else {
return $pageURL;


Add CSS & JS files in the plugin

function add_my_css_and_my_js_files(){
wp_enqueue_style( ‘my-stylesheet-name’, plugins_url(‘/css/style.css’, __FILE__));
wp_register_script( ‘my-plugin-script’, plugins_url( ‘/js/script.js’, __FILE__ ) );
add_action(‘wp_enqueue_scripts’, “add_my_css_and_my_js_files”);

Create table at the time of plugin activation

register_activation_hook( __FILE__, ‘create_table’ );

function create_table () {
global $wpdb;
$table_name = “table_name”;
$charset_collate = $wpdb->get_charset_collate();
$sql = “CREATE TABLE $table_name (
name text NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;”;

require_once( ABSPATH . ‘wp-admin/includes/upgrade.php’ );
dbDelta( $sql );
add_option( ‘normal_db_version’, $normal_db_version );

PHP error reporting

// Turn off error reporting

// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors

// Same as error_reporting(E_ALL);
ini_set(“error_reporting”, E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);

Drupal Articles Author and Date Information Display settings

1. Log-in as Admin and choose Structure, Content types and click edit (under Operations) for the corresponding content type (e.g. Article).
2. Click Display Settings and un-check Display author and date information check box.
3. Save settings by clicking the Save Content Type button.


1. Enable Display Settings for the corresponding content type.
2. Edit the node.tpl.php file of the corresponding theme you are using, e.g. themes\bartik\templates\node.tpl.php and located the following command:
print $submitted;

3. Now replace this command with the following code:
// print $submitted;
if ($submitted) {
echo "Posted: " . date( "F j, Y",$node->created);

4. Save the file and you should see the submitted information in the desired format. Of course, you can use a different date format or add additional node details.

Drupal basic codes

$GLOBALS['base_path']; // The base path to the Drupal installation. Usually this is just "/" or "/drupal" if you installed Drupal into a sub-directory.
$GLOBALS['base_url']; // The full URL to the Drupal installation (i.e. "" or "")
$site_frontpage = variable_get('site_frontpage', 'node'); // The site's configured frontpage path (i.e. "frontpage" or "node/123"), settable at http:// 
Is the user logged in?
if ($user->uid == 0) {
//user is not logged in