Categories
robot.txt WordPress

Block directories using robots.txt

Restrict search engines from crawling to the root directory by adding the code snippet below to robots.txt file.

User-agent: *

Disallow: /cgi-bin/

Disallow: /wp-admin/

Disallow: /wp-includes/

Disallow: /xmlrpc.php

Disallow: /wp-content/plugins/

Disallow: /wp-content/cache/

Disallow: /wp-content/themes/

Disallow: /trackback/

Disallow: /feed/

Disallow: /comments/

Disallow: /category/

Disallow: /trackback/

Disallow: /feed/

Disallow: /comments/

Disallow: /*?

Allow: /wp-content/uploads/
Categories
htaccess WordPress

WordPress Restrict access to wp-includes file via .htaccess fil

# Block wp-includes folder and files

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^wp-admin/includes/ - [F,L]

RewriteRule !^wp-includes/ - [S=3]

RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]

RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]

RewriteRule ^wp-includes/theme-compat/ - [F,L]

</IfModule>
Categories
WordPress

WordPress Redirect to a custom page after registration

function chet_tips_my_registration_redirect(){

    return home_url( '/my-page' );

}

add_filter( 'registration_redirect', 'chet_tips_my_registration_redirect' );
Categories
BuddyPress WordPress

Automatically add new users to BuddyPress group

function chet_tips_automatic_group_membership( $user_id ) {

 if( !$user_id ) return false;

 groups_accept_invite( $user_id, <# group ID #> );

}

add_action( 'bp_core_activated_user', 'chet_tips_automatic_group_membership' );
Categories
WordPress

WordPress Disable admin bar access to all users

If you want to disable access to admin bar for all the users including the administrator, add the following to the functions file.

show_admin_bar(false);
Categories
WordPress

WordPress Change the length of excerpts

function chet_tips_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length', 'chet_tips_excerpt_length', 999 );

By default, length of the excerpts in WordPress is 55 words. Tweak the functions by adding the following commands to customize the length so it can fit the layout.

Categories
PHP WordPress

WordPress memory exhausted error

If you were activating a huge plugin and found an error that says memory exhausted just add the following line of code to your wp-config.php file.

define('WP_MEMORY_LIMIT', '64M');

The above code will increase the memory limit to 64M, but you can change the value to whatever your hosting server is able to support.

Categories
WordPress

Add settings fields on options discussion admin page

You have to call add_settings_section() first, pass a unique ID and assign it to the page (poor name) discussion:

add_settings_section( 'ads_id', 'Extra Settings', 'ads_description', 'discussion' );

Then register a callback to save your field(s) …

// Register a callback
register_setting(
    'discussion',
    'ads',
    'trim'
);

… and then register one or more fields:

// Register the field for the "avatars" section.
add_settings_field(
    'ads',
    'Test field',
    'ads_show_settings',
    'discussion',
    'ads_id',
    array ( 'label_for' => 'ads_id' )
);

Here is a very simple example:

add_action( 'admin_init', 'ads_register_setting' );

/**
 * Tell WP we use a setting - and where.
 */
function ads_register_setting()
{
    add_settings_section(
        'ads_id',
        'Extra Settings',
        'ads_description',
        'discussion'
    );

    // Register a callback
    register_setting(
        'discussion',
        'ads',
        'trim'
    );
    // Register the field for the "avatars" section.
    add_settings_field(
        'ads',
        'Test field',
        'ads_show_settings',
        'discussion',
        'ads_id',
        array ( 'label_for' => 'ads_id' )
    );
}

/**
 * Print the text before our field.
 */
function ads_description()
{
    ?><p class="description">This is the description</p><?php
}

/**
 * Show our field.
 *
 * @param array $args
 */
function ads_show_settings( $args )
{
    $data = esc_attr( get_option( 'ads', '' ) );

    printf(
        '<input type="text" name="ads" value="%1$s" id="%2$s" />',
        $data,
        $args['label_for']
    );
}
Categories
MailChimp WordPress

MailChimp Get all subscribers emails from a list

WooCommerce
Categories
WordPress

How to Change the Login Logo in WordPress