Categories
Using WordPress

Best Codes in WordPress Functions.php File

All WordPress themes functions. php file comes with. This file acts as a plugin and WordPress on your site is very nice and lets you do useful things. In this article, WordPress functions.php file to show some of the most useful for function.

Before Helen’s picture Wondering What php File Funtions.;

Functions. php file is known as a WordPress theme functions file file. This file is all free and paid WordPress themes comes with.

The purpose of this file theme developers theme allow you to define the features and functions. This file is only function as a WordPress plugin and WordPress can be used to add your own custom code snippets in.

WordPress related articles by many suppliers on the site that you want to make functions with the given code snippets functions. php file, you are prompted to add your.

Here, you code snippets when you add to your php file functions. in fact add a small wordpress plugin to your site.

 Functions.php file is added to the code, or create a custom add-in to the site just below my article entitled share codes to your site when you add you will benefit.

Functions.php File you can add 25 Useful Code

Property: Enable Hidden Administrator That Displays All Site Settings Properties.

This small piece of code is doing something pretty sweet. Your site is bound to change all the settings in the database via the admin panel.

Among the features of WordPress, but by default inactive “all settings” link, under the Setup menu in the admin panel as an additional option.

In addition, when you add the following code to your php file functions. (see functions. php file is added to the code ) this all sets the tab Admin user accurately, while, for all other users.


   function all_settings_link() {
    add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
   }
   add_action('admin_menu', 'all_settings_link');

Property: Admin Panel Login Logusunu Replacement

If your site contains membership system or multiple author system, wordpress, you might want to change the logo in the input panel. To do this, the underlying code functions add to your .php file;


function custom_loginlogo() {
echo '<style type="text/css"> 
body.login div#login h1 a {
background-image: url(https://sizinsiteniz.com/logo.png);
}
.login h1 a {
background-size: 269px;
width: 269px;
height:60px;
</style>';
}
add_action('login_head', 'custom_loginlogo');

Ardıdan wordpress admin panel login if you want to change, with which logo the logo of the code found in the URL address, replace it with the URL address of your logo.

Your logo is the height and width settings you still code found in the background-sizewidth , and height can be set by changing values.

In addition, this process in connection with changing input panel wordpress logo is titled spelling you can get detailed information from.

In addition to login to the admin panel, so if you want to customize the complete Input Panel to change the design, you can take care of my titled.


Property: Turn Off All Non-Admin Users WordPress Update Declarations:

Below is my code in your php file verd when you add admin functions. users login to your site any user outside of wordpress yaptığıda wordpress update notifications.


       global $user_login;
       get_currentuserinfo();
       if (!current_user_can('update_plugins')) { // Kullanıcının eklentiyi güncelleme yetkisi olup olmadigina bakar 
        add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
        add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
       }

Property: WordPress jQuery Files via the Google CDN:

WordPress with your Google local jQuery script library, so your web site via the Google CDN optimizes performance and increases the speed of loading web site.

If you take the google CDN jQuery files via WordPress installed on your server will be deployed through the Google server load engine from your server, you will reduce your server load and less file to be loaded.

If you are using your own VPS, I do not recommend that you install the jQuery from other sources, but if you are using a shared hosting package, this method will certainly contribute to positive your site performance.

Below is my code in your php file verd when you add WordPress jQuery functions. files are no longer be drawn over google library. (WordPress is compatible for versions 3.1 and above)

//jQuery Google Library
function replace_jquery() {
 if (!is_admin()) {
 // comment out the next two lines to load the local copy of jQuery
 wp_deregister_script('jquery');
 wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false, '1.11.3');
 wp_enqueue_script('jquery');
 }
}
add_action('init', 'replace_jquery');

Property: Remove Security for WordPress Version Information:

Don’t show your WordPress version number publicly. To make this information public, the attackers of a particular version to take advantage of known vulnerabilities.

I gave the below code when you add your site to your php file functions. which you hide your wordpress version.


function complete_version_removal() {
 return '';
}
add_filter('the_generator', 'complete_version_removal');

Property: The front of your site, WordPress Comments not added any Links and Delete the part and unwanted in the figure the front of your site to Spam Comments Discarding or Managing by deleting:

The underlying code by adding your site to your .php file funcitons front in the comments section below, you can add unwanted and delete links. Thus the front of your wordpress site, you can manage the comments part.


function delete_comment_link($id) {
 if (current_user_can('edit_post')) {
 echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> ';
 echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>';
 }
}

Property: Recorded In The Database, The Preview Limits On The Number Of:

When you write your text on the front of your site to see how it will look when you use the preview feature of wordpress when you preview each database are recorded.

Using dozens of times a post preview feature when you examine, and when you write hundreds of articles on your site all of these recorded onboard an enormous load your database previews.

Such a load that your site’s database to delimit each wordpress preview records bindirememek’s I think a process to do.

Immediately below the code you add to your php file functions. I gave recorded preview drafts of max. 5 units with sınırlandırabilri.

/**
 * Onizlemeleri wp-config.php dosyasinda belirtilmedikce funcitons uzerinden sinirlandirma
 */
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 5);

Property: Resized Pictures In Terms Of Appearance Enhancement:

WordPress on your site when you resize the JPEG images, they can become a little fuzzy?

Here’s the underlying code functions when you add to your .php file, and as a result, whenever you resize the bulanıklaşan you can buy keskinleştirerek pictures sharper image;

Note: This property is only for pictures in JPEG fotmat.

function ajx_sharpen_resized_files( $resized_file ) {
$image = wp_load_image( $resized_file );
if ( !is_resource( $image ) )
return new WP_Error( 'error_loading_image', $image, $file );
$size = @getimagesize( $resized_file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
switch ( $orig_type ) {
case IMAGETYPE_JPEG:
$matrix = array(
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1),
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0; 
imageconvolution($image, $matrix, $divisor, $offset);
imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 90, 'edit_image' ));
break;
case IMAGETYPE_PNG:
return $resized_file;
case IMAGETYPE_GIF:
return $resized_file;
}
return $resized_file;
}   
add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files',900);
Resized Photos Sharpening php Code functions.

Property: “wordpress” As these words of “Moefycal wp WordPress” Just uninstall:

As you know, wordpress 3.0 I typed your site anymore after update on wordpress automatically post the anterior aspect of the word “WordPress”.

If you find it disturbing that State immediately below I share with code functions. php file, you can disable this feature by adding.

// P filtresi kaldırma
if(function_exists('capital_P_dangit')) {
foreach ( array( 'the_content', 'the_title' ) as $filter ) 
remove_filter( $filter, 'capital_P_dangit', 11 ); 
remove_filter('comment_text', 'capital_P_dangit', 31 );
}

Property: As The Summary Length Of The Manuscript Word Count Replacement:

Summer impressions of WordPress in the read more link for a summary of the number of words specified writing before 55. If you change the number of words between your portion of the theme features, that the underlying code functions. php in your file, you can change this by adding.

The underlying code that word count is increased to 100. If you if you want to change this number, change the number of the 100 in the code.

function new_excerpt_length($length) { 
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

Property: Admin Panel Posts/Pages on the tab Content was removed Forward Visuals also Listing:

I gave the below code when you add to your admin panel php file functions. articles/pages tab and this part was removed forward of content to be contained in images are listed at.

/****** Öne Çıkarılmış Görselleri Yazı/Sayfa Sekmesinde Gösterme ******/
if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) {
// for post and page
add_theme_support('post-thumbnails', array( 'post', 'page' ) );
function AddThumbColumn($cols) {
$cols['thumbnail'] = __('Thumbnail');
return $cols;
}
function AddThumbValue($column_name, $post_id) {
$width = (int) 35;
$height = (int) 35;
if ( 'thumbnail' == $column_name ) {
// thumbnail of WP 2.9
$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
// image from gallery
$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ($thumbnail_id)
$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
elseif ($attachments) {
foreach ( $attachments as $attachment_id => $attachment ) {
$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
}
}
if ( isset($thumb) && $thumb ) {
echo $thumb;
} else {
echo __('None');
}
}
}
// for posts
add_filter( 'manage_posts_columns', 'AddThumbColumn' );
add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 );
// for pages
add_filter( 'manage_pages_columns', 'AddThumbColumn' );
add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 );
}

Property: Take Care Of Your Site Your Own WordPress Sends Pingleri Closure:

Sometimes the wordpress site linkleme a post when you’ve established a post other than your internal link, you’ll get a pingback from yourselves (feedback). That’s when I gave code at the bottom when you add to your php file functions. This feedback closes.

//site için ping kapatma
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );

Property: Seçtirme First Official Story Was Removed Visually Stand Out Automatically:

Was removed a post in WordPress to add Visual post editor without forward “priorities identify visually”, you must add the official also.

Of course, the first official post in a post was removed automatically, it is possible to use as the picture forward. Many theme does this automatically. The people who did this are there plug-ins like Auto Post ThumbnailBut we don’t need to use the plugin for it. I gave the below code functions. php file will be enough to add.

add_filter('get_post_metadata', function($value, $object_id, $meta_key, $single) {
if ($meta_key !== '_thumbnail_id' || $value) {
return $value;
}
preg_match('~<img[^>]+wp-image-(\\d+)~', get_post_field('post_content', $object_id), $matches);
if ($matches) {
return $matches[1];
}
return $value;
}, 10, 4);

Property: Removing WordPress From Components By Default:

In General, most of us don’t use it (except for text component) of wordpress by default has brought a lot of components, components tab in your theme, and the components that it provides is also leads to an unnecessary when it comes to the crowd.

Well, if you’re like me this is unnecessary if you want to get away from the crowds below, when you add it to your php code I gave wordpress functions. by default, you can save all of the components.

// unregister all default WP Widgets
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
}
add_action('widgets_init', 'unregister_default_wp_widgets', 1);

Property: Post All Articles, Regardless Of The Format Of The Show Under Category Formats:

Any category when you add a post with a different typeface, your article may not go under the category you added. The underlying code is when you added your php file functions. all kinds of typeface category will take place under your.

function any_ptype_on_cat($request) {
if ( isset($request['category_name']) )
$request['post_type'] = 'any';
return $request;
}
add_filter('request', 'any_ptype_on_cat');

Property: The section of the WordPress Admin Panel, thank you For that you create with the Footer to change part of:

When you go to most any Admin Panel’s tab at the bottom “thanks for that you create with WordPress”, you will see a text in the form.

This is the text of the underlying code functions. php file and code as you want to, you can change by editing the article within.

Sometimes when you make a wordpress site for your customers to leave your own signature on this part, it may be useful to increase awareness of your brand name.

// Admin Footer
function custom_admin_footer() {
echo 'WPMAVI - WordPress Rehberi';
} 
add_filter('admin_footer_text', 'custom_admin_footer');

Property: Automatic Output Duration Extension:

Making the admin entry to your site after a certain period of time wordpress automatically gives you the output. Enter your home page to go back again, you’ll need to enter your user name and password.

When you add a php file, the underlying code is automatic functions. output duration 1 Yearbook. Thus 1 years wordpress automatically logout after a certain period of time you will have to make.

function keep_me_logged_in_for_1_year( $expirein ) {
return 31556926; // 1 year in seconds
}
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );

Property: Comment Removing This Link It Was Writer/Linklerini Remove Site Comments:

Although wordpress comment in comments gravatar profiles to your site as well as the name of the person who made that person as the site nofollow linklese, so that it didn’t, no problems in terms of SEO, the links are sometimes seriously irritating.

When you add to your underlying code functions .php file is put your site link throughout your site comments.


* @return string $author
*/
function wpse218025_remove_comment_author_link( $return, $author, $comment_ID ) {
return $author;
}
add_filter( 'get_comment_author_link', 'wpse218025_remove_comment_author_link', 10, 3 );


Property: Linklerdeki From latest WordPress Update with rel = “noreferrer noopener” Remove the label:

First of all, it belirtmeylim that noferrer and noopener have no effect on the label of SEO. This label update when you first came to people’s mind too much in terms of SEO.

What’s coming Upper Noreferrer: noferrer tag when a site you link out, link out to you use the site you made noreferrer tag comes from which source of traffic. So this tag means that references showing the person’s information.

Noopener What Does It Mean: Open in new tab of the link on your site, plants are a security vulnerability in the process. Your links to target = “_ blank” using the tag, the page you gave the link object through the EnvDTE.window.object opener to the previous partial access allows to provide.

This phishing attack means an opening for those who want to. Here is the latest update of wordpress so all interested in external links opened in new tab rel = “noreferrer noopener” label.

Normally, this code can be a healthy solution to this vulnerability. But there’s a problem if you are doing on your site if you affiliate and affiliate link contains these tags, links to your site that you can’t see where you’re coming from the traffic.

Although this does not directly impact your references sometimes can affect situations. I went through this too you statistically which also reference your link, you will not see you the most sales. Therefore, these tags are you statistics you just gave your marketing strategy decision.

If that’s the case if you are doing affiliate, phishing attacks out, rel = “noreferrer noopener” remove from your site, affiliate revenue, without affecting your context in order to be a good solution. However, please note that this is a risk.

The underlying code when you add your site to your php file functions. that you subsequently add to the external links now rel = “noreferrer noopener” etkiketi not added.

The external links in the article to the publication of this rel = “noreferrer noopener” effect is to remove the triangle, better search and replace using plug-ins like the next step must be changed over.

//Bu kodu kullanmanızı çoğu durumda önermem
add_filter('tiny_mce_before_init','tinymce_allow_unsafe_link_target');
function tinymce_allow_unsafe_link_target( $mceInit ) { 
$mceInit['allow_unsafe_link_target']=true; 
return $mceInit;
}

Property: S Image Front Post Linkleme:

Some of the themes presented to the screening of the article pages (home page, category pages to) post has been removed due to the front has not linked the picture post image.

If that’s the case for your site, the underlying code functions when you add to your .php file was removed up front for your posts will be linked to your post anymore pictures.

function wpmavi_autolink_featured_images( $html, $post_id, $post_image_id ) {
If (! is_singular()) { 
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
return $html;
} else {
return $html;
}
}
add_filter( 'post_thumbnail_html', 'wpmavi_autolink_featured_images', 10, 3 );

Property: Changing WordPress Default Image Link:

By default, when you insert a picture in a wordpress, image file or additional pages are automatically linked to/linklenir.

Users are directed to a new page when he or she clicks on the picture. This also means that the visitor left the page

WordPress default image Link – size – Alignment Change my article titled how to change wordpress default image settings detailed.

The underlying code functions. php file, just by adding wordpress you can also change the default image link;

function wpmavi_imagelink_setup() {
$image_set = get_option( 'image_default_link_type' );
if ($image_set !== 'none') {
update_option('image_default_link_type', 'none');
}
}
add_action('admin_init', 'wpmavi_imagelink_setup', 10);

After writing this code when you add pictures to your plugin automatically showing none of the connection settings option will in some way marked with light options.

 


Property: WordPress Admin Users:

WordPress admin user of your site, you can also add .php file via functions. All you have to do FTP to connect to your site with the server and when I gave code at the bottom functions. php file to add to your.

Of course the code found in Usurname – Password and e-mail address when you create request with admin user information.

function wpmavi_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','wpmavi_admin_account');

Property: Read More – Read Articles Like Changing The Text Section Of The Summary:

Article summary section of the text for the redirect the visitor to the article you want to change? To do this, all you need to do is add your page code I gave below functions .php.

Of course this is what the text you want to replace the code with read the rest part of the Co-Cathedral.

function modify_read_more_link() {
return '<a class="more-link" href="' . get_permalink() . '">Devamını Oku</a>';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );

Property: WordPress Site Search Function To Disable/Turn Off WordPress Site Search:

If your wordpress site search feature if you want to neutralize the bottom add to your my shared code functions .php file.

function fb_filter_query( $query, $error = true ) {
if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;
// to error
if ( $error == true )
$query->is_404 = true;
}
}
add_action( 'parse_query', 'fb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

Property: WordPress Default Gravatar Image Replacement:

WordPress is setup by default brought on by mystery man avatar on the underlying code functions by adding your own site to your .php file branded, you can change your avatar.

Before your site, add your new gravatar image through the Media tab and inserting it into the URL address located within the code with the URL address.

It then sets the >> Discussion >> Admin Panel go to the tab and selecting the new avatar image will appear at the bottom of the save changes. And that’s it.

add_filter( 'avatar_defaults', 'wpmavi_yeni_gravatar' );
function wpmavi_yeni_gravatar ($avatar_defaults) {
$myavatar = 'http://ornek.com/wp-content/uploads/2017/01/wwpmavi-yeni-gravatar.png';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}