8 Extremely Useful WordPress Functions For Developers
WordPress Functions
In WordPress Theme File We are seen /wp-cotent/theme/themeName/function.php File. as the name suggests, this file adds unique functions to your WordPress installation. This file works just like a plugin within your theme. So you can modify/override WordPress core features without editing any core file. If used correctly, this file can do wonders for your WordPress site. It also speeds up development because you can have all the codes at one place. In this article, we will share some of the most incredible and most wanted tricks for the WordPress functions.php file.
Note: The WordPress Functions Learners need some basic knowledge on php.
Why Use Functions.php / How To Make Functions?
WordPress is the world’s most powerful content management system. may wordpress helping the wordpress developers to make there own ability. web design include css and html coding. if you know css and html then you can make a good template. but it’s not enough for be a good designer and developer. each designer need art from soul then they can output there mind interesting. wordpress functions is enough for a blogger, but it not enough for a designer and blogger. useful wordpress functions you can make if you have idea about php. i like the wordpress functions, because of wordpress function.php file allow developers to modify the website functions with own mind. how to make functions? hey bloggers or developers, have a good news. today i’m going to show you some wordpress functions that may help you. scroll down and select your functions what you want to attach with your wordpress functions.
Add Google Analytic
The Google Analytic function help you to automatic add the google analytic into your each wp_footer string.You can paste the code once in your functions.php file and never have to worry about it again. google analytic function is a useful function whose has idea about google analytic. go to your wordpress theme function and add below code before closing ?> symbol.
<?php add_action('wp_footer', 'add_googleanalytics'); function add_googleanalytics() { ?> // Paste your Google Analytics code from Step 6 here <?php } ?>
For More: Google Analytic Details
Add Favicon Icon
This Function Will help you to add your website favicon icon that showing in browser.Every blog deserves to have its own identity. You can add this identity by adding the favicon code in your header.php file, or you can make it easier for yourself by simply adding the following code in your functions.php file. it can start affect after set this code into your wordpress theme function file.
// add a favicon to your function blog_favicon() { echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'http://cdn.wpbeginner.com/favicon.ico" />'; } add_action('wp_head', 'blog_favicon');
Hide WordPress Version Number
this functions is a great functions for developers. the functions will hide your wordpress version from others attacker and wordpress scan tools. so if you want this for your wordpress secure just place the below function.
function howtrick_remove_version() { return ''; } add_filter('the_generator', 'howrick_remove_version');
Custom Dashboard Logo
if you in your wordpress dashboard right now, follow left header in dashboard.you can see there have a Home icon,this function help you to place your own icon in there. place the function code into your wordpress function file.
//hook the administrative header output add_action('admin_head', 'my_custom_logo'); function my_custom_logo() { echo ' <style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; } </style> '; }
Custom Dashboard Footer
if you want to add your credit into wordpress dashboard, you can just need to edit this function and place into your wordpress theme function file. this function can showing your users and you in the wordpress dashboard footer what you edit.
function remove_footer_admin () { echo 'Fueled by <a href="http://www.wordpress.org" target="_blank">WordPress</a> | Designed by <a href="http://www.howtrick.com" target="_blank">Liton</a> | WordPress Tutorials: <a href="http://howtrick.com/related/wordpress" target="_blank">HowTrick.Com</a></p>'; } add_filter('admin_footer_text', 'remove_footer_admin');
Add Custom Dashboard Widgets in WordPress
You probably have seen widgets that numerous plugins and themes add in the WordPress dashboard. As a theme developer, you can add one yourself by pasting the following codes:
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 '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:info@howtrick.com">here</a>. For WordPress Tutorials visit: <a href="http://www.howtrick.com" target="_blank">HowTrick.Com</a></p>'; }
Change the Default Gravatar in WordPress
This Function is great and most useful for wordpress developer. it can change your wordpress default avatar from user profile picture.if a user never upload there profile picture, this function automatic add a profile picture by selected you. just copy the below code and past on function.php file.
add_filter( 'avatar_defaults', 'newgravatar' ); function newgravatar ($avatar_defaults) { $myavatar = get_bloginfo('template_directory') . '/images/gravatar.gif'; $avatar_defaults[$myavatar] = "HowTrick"; return $avatar_defaults; }
Don’t forget to upload a custom image to your theme’s image folder. Also change the name of the gravatar to their brand name. Once you upload the image and the functions, then visit: WP-Admin » Settings » Discussion
Dynamic Copyright Date in WordPress Footer
Dynamic copyright function will help you to no change your theme copyright year. it will automatic set and output present year and showing into your wordpress theme by using shortcode or php call function.
function comicpress_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; }
now past the below code where you want to show the dynamic copyright output.
<?php echo comicpress_copyright(); ?>
No More Today, I will coming back again for surprise you new wordpress functions.if you got any kind of problems with our code or instructions just drop your thought.
Post a Comment