Stop wasting time and money!

Easily create your WordPress website or blog today.

Elementor is the easiest and most importantly, the fastest tool to create any type of WordPress website or blog. No technical knowledge is required and is perfect for beginners or professional users. You can do it yourself so do it!

All WordPress themes come with a file " functions.php Powerful. This file acts as a plugin and lets you do a lot of cool things on your WordPress site. In this tutorial, we will introduce some useful tips that you can put together using this file functions.php.

Tips function php wordpress 1

What is the "functions" file on WordPress?

The functionality file is known as functions.php which is a functions file. WordPress themes. It is available in all free and premium WordPress themes.

The purpose of this file is to allow theme developers to define a theme's characteristics and functions. This file acts as a WordPress Plugin and can be used to add your own custom code snippets to WordPress.

Now you might be wondering what is the difference between a WordPress Plugin and the functions.php file? Which is the best ?

Although the functions.php file is more convenient, a specific plugin is much better. Simply because it is independent of your WordPress theme and will work no matter what theme you use.

On the other hand, the folder of a function theme will only work for that theme and if you change the theme then you will have to "copy / paste" your custom codes into the new theme.

That said, here are some very useful tips for the WordPress feature file.

1 - Delete the version of WordPress

You should always be using the latest version of WordPress. However, you may still want to remove the WordPress version number from your site. Just add this snippet to your "functions" file.

Function bpc_remove_version () {return ''; } Add_filter ('the_generator', 'bpc_remove_version');

2 - Add a custom logo on the dashboard

Want a white label on your WordPress dashboard? Adding a custom logo is the first step in this process.

First, you will need to upload your custom logo to your theme's images folder for example: custom-logo.png. Make sure your custom logo is 16 × 16 pixels.

After that, you can add this code to the function files of your theme.

function bpc_custom_logo () {echo '
#wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
background-image: url(' . get_bloginfo('stylesheet_directory') . '/images/custom-logo.png) !important;
background-position: 0 0;
color:rgba(0, 0, 0, 0);
}
#wpadminbar #wp-admin-bar-wp-logo.hover > .ab-item .ab-icon {
background-position: 0 0;
}
'; } // hook into the administrative header output add_action ('wp_before_admin_bar_render', 'bpc_custom_logo');

3 - Change the WordPress dashboard footer

The footer on the WordPress dashboard displays a message similar to this “Thank you for creating with WordPress”. You can change it by adding this code.

function remove_footer_admin() { echo 'Fueled by WordPress | WordPress Tutorials: BlogPascher '; } add_filter('admin_footer_text', 'remove_footer_admin');

Feel free to change it from a text and links that you want to add.

4 - Add custom widgets

You've probably seen widgets that many plugins and themes add to the WordPress dashboard. As a theme developer, you can add a widget yourself by pasting the following code:

add_action ('wp_dashboard_setup', 'my_custom_dashboard_widgets'); function my_custom_dashboard_widgets () {global $ wp_meta_boxes; wp_add_dashboard_widget ('custom_help_widget', 'Theme Support', 'custom_dashboard_help'); } function custom_dashboard_help () {echo ' Welcome to Custom Blog Theme! Need help? Contact the developer[email protected]">here . For WordPress tutorials visit: BlogPasCher '; }

5 - Change the default Gravatar default on WordPress

Have you seen the default mystery man on blogs? You can easily replace it with your own custom avatars. You just have to upload the image you want to use by default as an avatar then add this code to your "functions.php" file.

Add_filter ('avatar_defaults', 'bpc_new_gravatar'); Function bpc_new_gravatar ($ avatar_defaults) {$ myavatar = 'http://example.com/wp-content/uploads/2017/01/wpb-default-gravatar.png'; $ Avatar_defaults [$ myavatar] = "Default Gravatar"; Return $ avatar_defaults; }

Now you can go to " Settings> Chat And select your default avatar.

Wordpress default avatar

6 - How to add a dynamic copyright on the footer

You can just add the copyright date by changing the footer template in your theme. However, it won't show when your site started and it won't automatically change for next year.

You can use this code to add a dynamic time in the copyright on the foot of a WordPress page.

function bpc_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 function you will need to open your footer.php file and add the following code where you want to add a dynamic copyright date:


This function searches for the date of your first article, and the date of your last article. It then displays the years during which the function is called.

That's it for this hint list that you can apply to your functions.php file. If you have tips, you can also share them with us.

%d bloggers like this page: