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...

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...

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...

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...



1. is_page() :- Condition for check if page is displayed. Its return true or false.
2.
is_category() :- Condition for check if category is displayed. Its return true or false. 
3. wp_nav_menu() :- Enabling WordPress 3.0′s Navigation Menu Feature 
4. wp_list_pages() :- Listing All Pages in wordpress
5.
get_excerpt() :- Displays the excerpt of the current post with read more link for display full post. 
6. bloginfo(‘url’) :- Getting the Site’s URL
7. bloginfo(‘template_url’) :- Getting the URL to the Current Theme
8. the_content():- Displays the contents of the current post. 
9. the_title():- Displays the title of the current post.
10.the_time():- Display the time the post was published (uses PHP date formatting as a parameter)





Basic functions generally used in WordPress

Sangwan Pankaj Reply 01:31

1. is_page() :- Condition for check if page is displayed. Its return true or false. 2. is_category() :- Condition for check if c...

To disable the update in WordPress
First open functions.php file and write these lines in functions.php of your theme folder.

To Disable Core Updates of Wordpress
add_filter( ‘pre_site_transient_update_core’, create_function( ‘$a’, “return null;” ) );
wp_clear_scheduled_hook( ‘wp_version_check’ );

To Disable Theme Updates
remove_action( ‘load-update-core.php’, ‘wp_update_themes’ );
add_filter( ‘pre_site_transient_update_themes’, create_function( ‘$a’, “return null;” ) );
wp_clear_scheduled_hook( ‘wp_update_themes’ );

To Disable Plugin Updates
remove_action( ‘load-update-core.php’, ‘wp_update_plugins’ );
add_filter( ‘pre_site_transient_update_plugins’, create_function( ‘$a’, “return null;” ) );
wp_clear_scheduled_hook( ‘wp_update_plugins’ ); 
That it!

Disable Wordpress Updates

Sangwan Pankaj 1 11:59

To disable the update in WordPress First open functions.php file and write these lines in functions.php of your theme folder. To Disabl...

Use wp_get_current_user() to get current users value.
  wp_get_current_user() return WP_User object. 
<?php
    $current_user 
wp_get_current_user();
    
echo 'Username: ' $current_user->user_login '<br />';
    echo 
'User email: ' $current_user->user_email '<br />';
    echo 
'User first name: ' $current_user->user_firstname '<br />';
    echo 
'User last name: ' $current_user->user_lastname '<br />';
    echo 
'User display name: ' $current_user->display_name '<br />';
    echo 
'User ID: ' $current_user->ID '<br />';?>

Get current user data in wordpress

Sangwan Pankaj Reply 09:54

Use wp_get_current_user() to get current users value.   wp_get_current_user()   return WP_User object.   <?php     $current_user  =  ...

$new_general_setting = new new_general_setting();

class new_general_setting {
    function new_general_setting( ) {
        add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
    }
    function register_fields() {
        register_setting( 'general', 'profile_message', 'esc_attr' );
        add_settings_field('prof_message', '<label for="prof_message">'.__('Profile Share Message?' , 'profile_message' ).'</label>' , array(&$this, 'fields_html') , 'general' );
     }
    function fields_html() {
        $value = get_option( 'prof_message', '' );
        echo '<textarea id="prof_message" cols="100" rows="3" name="profile_message">' . $value . '</textarea>';
    }
}

post it in your functions.php file. and you can get the values anywhere by using 

$message_Profile = get_option( 'profile_message', '' );

Thanks!

Add Field to General Settings Page in Wordpress

Sangwan Pankaj Reply 10:15

$new_general_setting = new new_general_setting(); class new_general_setting {     function new_general_setting( ) {         add_filter(...

Add this line for instance into functions.php of your theme and you can run shortcodes in widgets.

add_filter('widget_text', 'do_shortcode');

Thats it!

Sangwan Pankaj Reply 23:20

Add this line for instance into functions.php of your theme and you can run shortcodes in widgets. add_filter('widget_text', ...

Wordress

Sangwan Pankaj Reply 23:07

WordPress is web software you can use to create a beautiful website or blog. We like to say that WordPress is both free and priceless at...

Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us