Here, we are going to explain how to update copyright notice automatically in Wordpress.

If you ever noticed that most of the websites forgot updating the year in the copyright notice which is a very little and easy task. The one way you can update your copyright by using this trick, it automatically generates the copyright date based on the year.

We are going to write a code for this trick here and will paste the following code into Theme's functions (functions.php) file.


function wpb_copyright() {
    global $wpdb;
    $copyright_dates = $wpdb->get_results("
    SELECT
    YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate
    FROM
    $wpdb->posts
    WHERE
    post_status = 'publish'
    ");
    
    $output = '';

    if($copyright_dates) {
        $copyright = "© " . $copyright_dates[0]->firstdate;
        if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
        $copyright .= '-' . $copyright_dates[0]->lastdate;
        }

        $output = $copyright;
    }
    return $output;
    }

After adding this code in functions, you will need to open footer.php file and add the following code below wherever you want to display. It will updating dynamically  on your website.
    
    //echo wpb_copyright(); add the following code wherever you want the copyright information to be displayed

we added the copyright code in the footer.php file so it would be displayed at the bottom of the website.

 Enjoy!!

Automatically Update Your Copyright Notice in Wordpress

Sangwan Pankaj Reply 04:52

Here, we are going to explain how to update copyright notice automatically in Wordpress. If you ever noticed that most of the websites forgo...

we will create a simple widget,See this code and then paste it in your site-specific plugin or functions.php file to see it in 
action.  
 
 
// Creating the widget 
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(
// Base ID of your widget
'wpb_widget', 

// Widget name will appear in UI
__('WPBeginner Widget', 'wpb_widget_domain'), 

// Widget description
array( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ) 
);
}

// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];

// This is where you run the code and display the output
echo __( 'Hello, World!', 'wpb_widget_domain' );
echo $args['after_widget'];
}
  
// Widget Backend 
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'wpb_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php 
}
 
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class wpb_widget ends here

// Register and load the widget
function wpb_load_widget() {
 register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );
 
 
 

Create Custom Widget in Wordpress

Sangwan Pankaj Reply 18:17

we will create a simple widget,See this code and then paste it in your site-specific plugin or functions.php file to see it in action.   ...

With the last version of PHP, there are many actual methods included in the core language that you should use in your code files. These will help you a lot that you might have working out the easist way to creat a salt. So, if you are able to do, I suggest you to switch to using this method everywhere (if possible) you generate passwords.

Hashing Logic is as simple as you doing this:

password_hash('YouRSuperSecure&(*$p880$0w0rd!', PASSWORD_BCRYPT);

Here, you pass in the string that you want to hash, and the method of hashing that you’re looking to use. You can add the second parameter, and stick to the default that PHP chooses to the best.

By default the method will use a cost of 10, which is a good level to start at, however if you want to change this, you can pass through the cost as a third parameter as an array of options.

See below example sets the cost value to 16 (min is 4, max is 30)

Example:- 

password_hash('YouRSuperSecure&(*$p880$0w0rd!', PASSWORD_BCRYPT, ['cost' => 16]);


It’s just that easy like anything! Enjoy!. 

Please do share our blog with interested coders and those you always ready to learn. 

Hashing Passwords with PHP Coding

Sangwan Pankaj Reply 02:50

With the last version of PHP, there are many actual methods included in the core language that you should use in your code files. These wil...

How to Insert data into table from excel file in php


Step 1:- Open an excel file and save as "Excel Data" text file and in below sample code, "test.txt" is excel-data excel file.

Step 2:- Now, follow the below instruction for create code for insert data into table in mysql using php.


<?php
  include 'config.php';
// Connect to your database.

$fp = fopen("test.txt", "r");    // Open that file('Excel Data') for reading

while($line = fgets($fp))      // Loop through each line
{

     list ($name, $first) = explode("\t", $line);

     // Split the line by the Excel Data and store it in our list...

     $sql = "insert into user (name,phone) values ('$name', '$first')";

     // Generate sql string...

     mysql_query($sql) or die ( mysql_error() );        // Execute the sql

}

?>

Step 3:- Run file.

How to Insert data into table from excel file in php

Sangwan Pankaj Reply 00:29

How to Insert data into table from excel file in php Step 1:- Open an excel file and save as "Excel Data" text file and in bel...


I am going to share a complete solution to help people out with updating XAMPP in Windows. Let's start step by step guide to upgrade XAMPP that actually works!

While updating XAMPP we basically face few challenges like - 


  1. Moving all the site files from xampp folder. This portion is easy just a simple copy paste will do the trick.
  2. Moving all the databases to the new server. And most often this is the main issue why we don’t update XAMPP very often. Cause backing up all the databases one by one and then importing them to new server is really a long boring work.

Now Follow the following steps!

BACKUP OLD DATA!

Lets backup all the databases from xampp,
  1. Open XAMPP Control Panel as an Administrator
  2. Click on the Shell option
  3. run the following command - mysqldump -u root -p --all-databases > all-db-dump-backup.sql
  4. If you have different user for databases then change the value ‘root’ with username. If you don’t have any password just press enter. Otherwise provide the password.
  5. This will create a SQL file named “all-db-dump-backup.sql” that contains all the databases in MySQL server. You will find this file in xampp folder.
  6. Now stop both Apache and MySQL servers and quit the xampp control panel. Close the command prompt too.
  7. Now rename your ‘xampp’ folder to ‘xampp-old’. This way if anything goes wrong you will be able to get back to the old version very easily.


NOW INSTALL THE NEW XAMPP!


  1. Download the latest version of XAMPP.
  2. Install it in the same drive where your old xampp currently installed.
  3. Now run the xampp control panel as Administrator.
  4. Start both Apachee and MySQL server and check whether they are working properly or not, also check PhpMyAdmin page.
  5. Now Copy the htdocs folder from ‘xampp-old’ folder to ‘xampp’ folder.
  6. Go to xampp\php\php.ini
  7. You can use CLI for importing database. It specially helps with very big databases. If so you can jump to step 19. If not follow the remaining steps.
  8. Now configure the php.ini file and increase the value for the following options upload_max_filesize,memory_limit, post_max_size .
  9. post_max_size and memory_limit need to be larger than upload_max_filesize. Make them high enough so big files can work on the server.
  10. Go to ‘xampp\phpMyAdmin\libraries\config.default.php
  11. Look for $cfg[‘ExecTimeLimit’] = 800;
  12. Change the value 800 to a higher value may be 8000.
  13. Now restart both Apache and MySQL server.
  14. Now go to phpMyAdmin then Go to Import tab
  15. Import ‘all-db-dump-backup.sql’ file through the import option directly to server.
    Based on how many databases you have it will take some time.
  16. If you have followed all the steps correctly you will get a success message “ Import has been successfully finished”.
  17. After that run the following command mysql_upgrade in the Shell option.
  18. Go ahead and check whether your site and databases are working properly or not.
  19. If everything is working fine than you can delete the xampp-old file.
If you have followed my instructions then you should have a functioning XAMPP with no issues. If you do face any problem then please leave a comment and I will do my best to get back to you.  Enjoy!!
 

How to upgrade XAMPP in Windows? PHP 5 to 7 version

Sangwan Pankaj Reply 15:26

I am going to share a complete solution to help people out with updating XAMPP in Windows. Let's start step by step guide to upgrade...

How can You get table cell values and cells text boxes values?That means getting childNodes values using java script.This is easy using core javascripts.

Returns a nice array of your data, then you can display it how you want.

function updateRowData(id) {
    if(confirm("Are you sure you want to update this row?")) {
    //    alert(id);
       
        $("tr#table-row-"+id).click(function() {

//var tableData = $("tr#table-row-"+id).children("td").map(function() { // you can use this also but you need to comment upper line ( $("tr#table-row-"+id).click(function() { ) and uncomment this line   
  var tableRow = $(this).children("td").map(function() {
        return $(this).text();
    }).get();

    alert("Your data is: " + $.trim(
tableRow[0]) + " , " + $.trim(tableRow[1]) + " , " + $.trim(tableRow[2]));
});

    }
}

onClick get row values from Html table

Sangwan Pankaj 1 10:02

How can You get table cell values and cells text boxes values?That means getting childNodes values using java script.This is easy using ...

At the time functions.php is included during bootup, WordPress has no idea on the contents of the query, and doesn't know the nature of the page. is_home will return false.

Wrap the code in a function and have it triggered by the wp hook, which comes after the global query object has been hydrated with data.


add_action( 'wp', 'check_homepage' );
function
check_homepage() {
    if ( is_home() )
        add_action( 'wp_enqueue_scripts', 'my_scripts' );
}

is_home() is not working in functions.php

Sangwan Pankaj Reply 04:15

At the time functions.php is included during bootup, WordPress has no idea on the contents of the query, and doesn't know the nature of...

add_filter('the_content', 'trim_content');

// This function use to modify you content functions
function trim_content($content){
  $word_limit =30;
  $words = explode(' ', $content);
  return implode(' ', array_slice($words, 0, $word_limit));
}


OR

add_filter('the_content', 'trim_content');

// This function use if  the content having more than 100 charaters it converts into excerpt format.
function trim_content($content)
{
    if(is_archive())
    {
       
// I'm getting the first 100 characters just to show an example you can change the value to get the words..
        $content = (strlen($content) <= 100)? $content : wp_html_excerpt($content, 100);
    }

    return $content;
}

Limit Words and Characters in content WordPress

Sangwan Pankaj Reply 21:22

add_filter('the_content', 'trim_content'); // This function use to modify you content functions function trim_content($c...

If you really want to disable Updates and Installations, you can block users from installing/updating themes and plugins through the dashboard. Add this quick snippet to your wp-config.php file:

define('DISALLOW_FILE_MODS',true);

It will prevent users from installing and updating themes and plugins. It will also automatically disable theme and plugin editing in the dashboard.


Disable Plugin and Theme Update and Installation

Sangwan Pankaj Reply 13:02

If you really want to disable Updates and Installations, you can block users from installing/updating themes and plugins through the dashbo...

Access to plugin and theme code is available in the WordPress dashboard. You can do one thing to protect the site from trifile to disable the both of these editors. Open your wp-config.php file and add the following constant:

define('DISALLOW_FILE_EDIT',true);

Now, when you are in the dashboard it is impossible to access the theme or plugin editor, even if you are admin.

Disable the Plugin and Theme Editor

Sangwan Pankaj Reply 12:57

Access to plugin and theme code is available in the WordPress dashboard. You can do one thing to protect the site from trifile to disable t...

In this tutorial, i will share how to send Email from XAMPP (PHP). i use XAMPP 1.8.1 version .This has been tested by me and it worked.

Lets start:-
first always make a backup before changing any code in core/configuration files.
then

Edit your php.ini in - “xampp\php\php.ini”

Before Changes:- 
---------------------------
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesD:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.

; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"\XAMPP\sendmail\sendmail.exe\" -t"

After Changes :-
-----------------------
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = yourgmailid@gmail.com

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesD:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.

; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"\XAMPP\sendmail\sendmail.exe\" -t"

now

Edit your sendmail.ini - “xampp\sendmail\sendmail.ini”

smtp_server=mail.mydomain.com or smtp_server=localhost

; smtp port (normally 25)
smtp_port=25

comment these two lines using - ;


;smtp_server=mail.mydomain.com or ;smtp_server=localhost
; smtp port (normally 25)

;smtp_port=25



and add some extra code in the bottom of your sendmail,ini:

;new config:
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log
pop3_server=
pop3_username=
pop3_password=
force_recipient=
hostname=
auth_username=yourgmailid@gmail.com
auth_password=your gmail password
force_sender=yourgmailid@gmail.com

NOTE: 
  1. You Need to restart xampp after saving both files.
  2. Change yourgmailid@gmail.com & your gmail password  with your own email id and password
  3. You Need to enable SMTP in your GMail to make this work and all sender will be from your email (if need).





Enable Send Email in XAMPP (localhost)

Sangwan Pankaj Reply 11:27

In this tutorial, i will share how to send Email from XAMPP (PHP). i use XAMPP 1.8.1 version .This has been tested by me and it worked. L...

Hi, in this tutorial we will discuss on current website url and current / working directory name

First you can get the name of the website by using

<?php echo $_SERVER['SERVER_NAME']; ?>
or
<?php echo $_SERVER['HTTP_HOST']; ?>

Now you can get the directory name

<?php echo dirname($_SERVER['PHP_SELF']); ?>

NOTE:
(if you are working on  multi folders and you need parent folder you can use 'dirname()'  function multi times

Example if you using 2 folders like /manage/user/ and you need parent folder only (i.e manage)

<?php echo dirname(dirname($_SERVER['PHP_SELF'])); ?>

you will get /admin result.

 )

Now the complete path

<?php echo "http://".dirname($_SERVER['SERVER_NAME']."".$_SERVER['PHP_SELF']); ?>

Result:  http://www.example.com/manage/user

and

complete the path with parent directory name

<?php echo "http://".dirname(dirname($_SERVER['SERVER_NAME']."".$_SERVER['PHP_SELF'])); ?>

Result:  http://www.example.com/manage






How to get working website path & directory name?

Sangwan Pankaj Reply 12:35

Hi, in this tutorial we will discuss on current website url and current / working directory name First you can get the name of the websit...

Put this code in functions.php file
<?php

if ( ! function_exists( 'wp_pagination' ) ) :
function wp_pagination() {
global $wp_query;

$int_val= 99999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $int_val, '%#%', esc_url( get_pagenum_link( $int_val) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
endif;

?>

and put this code anywhere for pagination

<?php wp_pagination (); ?>

Pagination function in wordpress for posts

Jimmy Wales Reply 14:55

Put this code in functions.php file <?php if ( ! function_exists( 'wp_pagination' ) ) : function  wp_pagination () { glo...

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomStringValue = '';
    for ($i = 0; $i < $length; $i++) {
        $randomStringValue .= $characters[rand(0, strlen($characters) - 1)];    }
    return $randomStringValue ;}
Output the random string :-
// Echo the random string.
echo generateRandomString(); 

PHP random string generator function

Jimmy Wales Reply 15:46

function generateRandomString ( $length = 10 ) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ...

Just keep a counter, increment it in the loop, and if it's an odd number set class to odd, if even set class to even. 
$result  = "";
$count = -1;

while ( $row = mysql_fetch_assoc( $query) ) {
  $class = $count++ % 2 === 0 ? "even" : "odd" ;
  $href  = $row["url"];
  $text  = $row["name"];
  $output .= "<li class='{$class}'><a href='foo?id={$href}'>{$name}</a></li>";
}

echo "<ul>{$result}</ul>";

Displaying database records in unordered list format

Jimmy Wales Reply 09:52

Just keep a counter, increment it in the loop, and if it's an odd number set class to odd, if even set class to even.  $result = ...

Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us