Remove the shortcode from get_the_content

 

step1: Remove the shortcode from get_the_content():

<?php
  //Remove the shortcode from content
  $content = strip_shortcodes(get_the_content());
?>

 

step2: Remove shortcode on home page but not on single or archive pages(function.php):

<?php
  /*
  * Remove shortcodes on the home page
  *
  */
  function remove_shortcode_from_home( $content ) {
     if ( is_home() ) {
         $content = strip_shortcodes( $content );
     }
     return $content;
  }
   add_filter( 'the_content','remove_shortcode_from_home' );
?>

Search Results Filter

Search Filter :

Step 1: WordPress Search Result Fillter function

Put this code in function.php

<?php 
//Hook to Search result
function SearchFilter($query) {
    if ($query->is_search) {
        $query->set('post_type', 'post');
    }
    return $query;
}
add_filter('pre_get_posts','SearchFilter'); 
?>

This function is only filer the posts in search results.

Step 2: WordPress Search Result Fillter With Pages functions

<?php 
//Hook to Search result
function SearchFilter($query) {
    if ($query->is_search) {
        $query->set('post_type', 'post', 'page');
    }
    return $query;
}
add_filter('pre_get_posts','SearchFilter'); 
?>

This function is filer the posts and pages in search results.

Disable the Admin Bar

Step 1: Disable Admin Bar for All Users Except for Administrators

Add below code in function.php :

<?php add_action('after_setup_theme', 'remove_admin_bar');
 
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
} ?>

 

Step 2: Disable Admin Bar for All Users

<?php show_admin_bar(false); ?>

Add CSS into wordrpess admin

Add below code into function.php within the active theme folder.

<?php
add_action('admin_head', 'your_custom_func');
function your_custom_func() {
echo '<style>
/* Add your custom style here */
</style>';
}
?>

Above code will add the style into admin header.
admin_head — Admin header hook. Its hooked by add_action.

WooCommerce products per page and List all products

Add below code in function,php to list only particular count product in product list page. Below code will list 12 products per page.

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ) );

Use below code to list “All products” in one page.  So, URL should have “URL?showall=1

if( isset( $_GET['showall'] ) ){
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return -1;' ) );
} else {
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ) );
}

WordPress Security

Follow the below steps to secure your Blog

  1. Block wp-config file access.
    Add below code into “.htaccess” file which is in your root folder. Place this code outsideof the  # BEGIN WordPress and # END WordPress tags.
    <files wp-config.php>
    order allow,deny
    deny from all
    </files>
  2. Disable Directory access through Browsing
    # Disable directory browsing
    Options All -Indexes

  3. Securing wp-includes and wp-admin includes.
    Includes folder is common for all wordrpess site. So, we need to secure this folders. Add below code in “.htaccess” file.
    # Block the include-only files.
    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]
  4. Change and make sure the file permission
    Below is the default file permission for Files and Folder. Please check it and make sure its not changed into any other permission.Need to change the common file permission as like below. We could do it through FTP.
    wp-config.php(root) file permission set to 440 or 400
    – All directories set to 755 or 750
    – All files set to 644 or 640
  5. Disable File Editing
    In Wordrpess admin we have the option to edit the theme files, using below code we could disable that option.
    define('DISALLOW_FILE_EDIT', true);
  6. Remove the WordPress version
    Add below code into the wp-config.php file to remove the WordPress version from user-end
    remove_action('wp_head', 'wp_generator');