Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Saturday, September 26, 2015

Remove Multisite Option from Wordpress

WordPress blog when you want to create multi language or multi site than it allow you option by some changes in coding. This functionality is useful when you want to set different post content for each website or many countries, languages then you must create multi website. Multi site also use when you want to create multi domain website.
To Enable multi site option or create a multi site in your current WordPress website than see details here.
Some times you does not need multi website option or back to same or original wordpress site from multi website than here simple and basic steps for remove multi website or network option in WordPress
  1. Open your wp-config file on WordPress root folder
  2. Find define('WP_ALLOW_MULTISITE',true); and replace to define('WP_ALLOW_MULTISITE',false);
  3. Remove below code from that file which is added during create multi site

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', false );
    $base = '/wordpress/';
    define( 'DOMAIN_CURRENT_SITE', 'localhost' ); //Server path
    define( 'PATH_CURRENT_SITE', '/wordpress/' ); //WordPress directory name
    define( 'SITE_ID_CURRENT_SITE', 1 );
    define( 'BLOG_ID_CURRENT_SITE', 1 );
  4. Delete current .htaccess file and recreate by default WordPress(Login to admin panel and change permalink than .htaccess auto generate if folder permission is 777)
  5. Now enter into phpMyAdmin for database access.
  6. Remove spam and deleted field from wp_users table (where 'wp_' is table prefix). Enter below sql query for that.

    ALTER TABLE `wp_users` DROP `spam`, DROP `deleted`;
  7.  Delete all tables which are related to second blog like `wp_2_commentmeta` where 2 is site id of second site which you can find in wp_site table
  8. Now delete all below tables for multi site
    • wp_blogs
    • wp_blog_versions
    • wp_registration_log
    • wp_signups
    • wp_site
    • wp_sitemeta
    For delete above tables use below sql query

    DROP TABLE `wp_blogs`, `wp_blog_versions`, `wp_registration_log`, `wp_signups`, `wp_site`, `wp_sitemeta`;
Run website and check admin panel multi site option was removed.

Sunday, July 26, 2015

Convert WordPress Menu to Bootstrap Navigation Menu

WordPress is using for blogging and simple information website, Now every website required responsive for comparable all devices (Mobile, Tablet, Desktop) for that every website, create as responsive site. From that Bootstrap is most known as HTML, CSS and JavaScript platform for developing responsive website. So there are many WordPress free and paid theme available based on bootstrap platform.
When you create your own theme in WordPress using Bootstrap platform that most conman problems is converting WordPress menu to Bootstrap navigation menu. Here display solution for converting WordPress menu to Bootstrap navigation menu without using any extra script or function. Convert WordPress menu to Bootstrap using jQuery.
For download and use Bootstrap see main website http://getbootstrap.com/
Integrate Bootstrap into WordPress website add below script and CSS in header.php file.

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Here enter CSS and script path according to Bootstrap path in your theme.
Now create any WordPress menu from admin panel Appearance->Menu.Save that menu with menu name.Now display menu anywhere in website using `wp_nav_menu` function as below.

wp_nav_menu(array('menu'=>'Main menu','menu_class'=>'nav navbar-nav','container'=>''));

Now convert menu to Bootstrap using jQuery.for that add latest jQuery script if not use in theme as below.(In WordPress already define jQuery in `wp_head()` function)
Now add below script for menu.

<script>
jQuery(document).ready(function(){
    jQuery("#menu-header-menu li").each(function(){
     if(jQuery(this).children('ul').length)
  {
   jQuery(this).addClass('dropdown');
   jQuery(this).children('a').addClass('dropdown-toggle');
   jQuery(this).children('a').attr('data-toggle','dropdown');
   jQuery(this).children('ul').addClass('dropdown-menu');
  }
    });
    //This jQuery use for a link redirection in Bootstrap navigation.
    jQuery('ul.nav > li a').click(function(e){
 window.location = jQuery(this).attr("href");
    });
});
</script>
 
Now check website in browser WordPress menu convert into Bootstrap navigation menu.This script use only first level of WordPress menu not use for WordPress M=multi level menu.

Monday, June 29, 2015

Disable Update Notification in Wordpress Without Plugin


WordPress provide auto update functionality for update all sources and plugin with the latest updated from it's admin panel which is called `wp-admin`. After some specific time or event update function of Wordpress finds the latest version of exiting resources from the internet and also provide direct download and install to current resource functionality.
This is very nice functionality for use latest version and updated functions and supports of Wordpress. But Sometimes when you make some customize of Wordpress functionality by modification of files than when you upgrade than previous updated files removed and replace it to a new file and again make changes to new file according to theme or customization so that time must stop upgrade the latest version of Wordpress resource.
When an update available than in admin panel display notification for update version so you must remove that notification for stop update.
In Wordpress there are three types of  update.

1) Wordpress Core Update 

This update is for change Wordpress version to latest version and update all Wordpress core functionality and files which are in `wp-include` and `wp-admin` folder.Wordpress core update notification display at the header of the admin panel. so remove that notification by two ways.
  • Edit File
    For stop Wordpress core notification just set Wordpress version to latest version.Wordpress define it's version as global variable as `$wp_version` in wp-include/version.php file.So just change new version in that variable.For these changes must check Mysql and PHP version and comparability.
  • Modifying Core Functions
    Wordpress check latest version according to last checked time so changed that time to latest time.for that add below function in theme `function.php` file
    
    function remove_core_updates(){
     global $wp_version;
     return(object) array('last_checked'=> time(),'version_checked'=> $wp_version);
    }
    add_filter('pre_site_transient_update_core','remove_core_updates');
    

2) Wordpress Plugin Update

Wordpress plugin update notification display in `Update` and `Plugins` menu so remove that notification as below.
  • Edit File
    For stop Wordpress plugin update notification just change the version to latest version in the plugin main file where define plugin name and description.
  • Modifying Core Functions
    Add below function in theme `function.php` file or plugin file.
    
    function remove_plugin_updates(){
     global $wp_version;
     return(object) array('last_checked'=> time(),'version_checked'=> $wp_version);
    }
    add_filter('pre_site_transient_update_plugins','remove_plugin_updates');
    
    or use below code for any specify plugin
    
    function stop_plugin_updates( $value ) {
        unset( $value->response['akismet/akismet.php'] ); //Plugin file name
        return $value;
    }
    add_filter( 'site_transient_update_plugins', 'stop_plugin_updates' );
    

3) Wordpress Theme Update 

Wordpress theme update notification display in `Update` and `Appearance` menu so remove that notification as below.
  • Edit File
    For stop Wordpress them update notification just change the version to the latest version of theme `style.css` file where theme name and description define.
  • Modifying Core Functions
    Add below function in theme `function.php` file.
    
    function remove_plugin_updates(){
     global $wp_version;
     return(object) array('last_checked'=> time(),'version_checked'=> $wp_version);
    }
    add_filter('pre_site_transient_update_themes','remove_theme_updates');
    
Here when you changes in a file for remove update notification than every time you make changes in the file whenever a new update available. So it's better to add new functions for stop update notification. Here single function use for stop all Wordpress notifications as below.

function remove_all_updates(){
 global $wp_version;
 return(object) array('last_checked'=> time(),'version_checked'=> $wp_version);
}
add_filter('pre_site_transient_update_core','remove_all_updates'); // Core update
add_filter('pre_site_transient_update_plugins','remove_all_updates'); //Plugin update
add_filter('pre_site_transient_update_themes','remove_all_updates'); //Theme update

Wednesday, June 10, 2015

Valid Wordpress Comment Before Submit

For Wordpress Blog comment is most important for make complete Wordpress blog website and comment features.When you create any any wordpress website than comment is also include in default wordpress functionality.Wordpress also allow comment on any page and custom create post type.
If you want to remove comment functionality for page or post than edit that post and remove discussion check box in discussion meta box.If you want to remove comment functionality from any post type than remove 'comments' in `register_post_type`'s 'supports' parameters.
When you use Wordpress default comment functionality than  when any use click on submit button without enter name,email and comment than it's display blank screen and error display as below.

ERROR: please fill the required fields (name, email).

So if you want to change this steps and do not accept form without enter validation field than must validate comment form before submit using jQuery validation.
  1.  Download latest jQuery Validated file from http://jqueryvalidation.org/
  2. Call script file in header.php file of current theme directory as `
    <script src="<?php bloginfo('template_directory');?>/js/jquery.validate.js"></script>
    `
  3. Open comment.php file of theme (If not exits create new based on Wordpress default theme) and enter validation script for comment form as `jQuery("#commentForm").validate();`
Now without email,text and comment text not accept comment form and it's validated using jQuery validation.

Thursday, June 4, 2015

Solve Unknown collation: 'utf8mb4_unicode_ci' Error in Wordpress

If you use Wordpress for Blog/Website or are you Wordpress developer than must know import and export database for upload website on live or move website from one server to another server.
If you want to change Wordpress website server live to local or move website than another server than first export old Wordpress database and than upload it to new server than sometimes you fetch below error in cpanel phpMyAdmin.

#1273 - Unknown collation: 'utf8mb4_unicode_ci'

This error because of change php version if php version is higher than 5.5 than it save all database as 'utf8mb4_unicode_ci' and that database import to lower version of cpanel than it's display below error. Solve that error just exporting database according to below step for import it on lower version of PHP.

1) Select database of phpmyadmin.
2) Click on 'Export' tab on database.
3) Select `Custom` Export Method.
4) Select tables from list of all database tables for export.
5) Select `Format-specific options`->'Database system or older MySQL server to maximize output compatibility with' MYSQL40 instead of NONE.
6) Click on GO button at bottom for export.
7) Save exporting database.

Now import new exporting database to new server it's install successfully.Here from below step 5th step is most important and compulsory for solve 'Unknown collation' error.

Saturday, May 9, 2015

Custom integration of Google Translate in website

If you are developer or site owner and want to create multi language website using google translate than must add google translate toolbar easily from your google account Website Translator.Google provide you source code for your website just copy and past it to your website according to your setting that you set while create translate toolbar from Google Account.See complete steps.
When you want to add google translate with custom option like as check box,radio button,drop down or listing event for change language than need to old translate code as below.
Add translate script at head of website
 
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript">
 
Set new translate element for define translate languages.
 
<script>
function googleTranslateElementInit() {
      new google.translate.TranslateElement({ includedLanguages: 'en,ar,hi,fr', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>

Here in  'includedLanguages' set all languages code that you want to translate here include only 4 languages.
Create list for change language with onclick event.


<li><a onclick="return ChnageLang('ar')" title="ar">العربية -  Arabic</a></li>
<li><a onclick="return ChnageLang('')" title="ar">English  -  English</a></li>
<li><a onclick="return ChnageLang('fr')" title="ar">Français  -  French</a></li>
<li><a onclick="return ChnageLang('hi')" title="ar">हिंदी  -  Hindi</a></li> 
 
Here create new 'ChnageLang' event when click on below list for change language.
 
<script>
      function ChnageLang(value){
       createCookie('googtrans','/auto/'+value,1,'');
      }
      function createCookie(name, value, days, domain) {
         var date = new Date();
         date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
         var expires = "; expires=" + date.toGMTString();
         document.cookie = name + "=" + value + expires + "; domain=" + domain + "; path=/"';
      } 
</script>

Sunday, February 1, 2015

Change all Posts Published Date in Wordpress


In Wordpress all blog or post save as current post time or set publish post as own date and time.According to publish date & time all post display as archive label `Publish on`. Also this useful for search result for own Website.
So when you chnage server or upload website from localhost to live server than its necessary to change all post publish date same as upload website on server date.
If you want to change a single post publish date than it's Manage from admin panel but when you want to change publish date for all post than must use PHPMYADMIN.
Here below describe two way for change post publish date.

1. From Admin Panel

  1. Login to your website's admin panel.
  2. Go to all posts page from left menu.
  3. Here display list of post select Quick Edit link which post you want to change date.
  4. Change that date and update post.

2. By Phpmyadmin

If you have Phpmyadmin details than change post publish date directly from database.
All post publish date save as `post_date` & `post_date_gmt` so open `wp_post` table and change that two column value for particular post.

3. By Mysql Query

If you are developer than it is easy for change post date by using SQL query in WordPress as below.

global $wpdb;
$wpdb->query("UPDATE `".$wpdb->prefix."posts` SET 
`post_date` = 'DATE(Y-m-d H:i:s)',
`post_date_gmt` = 'DATE(Y-m-d H:i:s)' WHERE `ID` = 'POSTID'");
 
Here Replace your post or page id instead of POSTID and set date as below format.Here if you want to change all pots publish date that you can do using loop.

Friday, January 30, 2015

Preventing P and BR Tags in WordPress Posts


In Wordpress when you create new post or page from admin panel and when you write some content and save that post that in fronted auto add <p>..</p> and <br/> tags which display extra spaces and some times it's effect current Wordpress theme. so it must be remove from stop extra spaces in Wordpress.

This happen because of WordPress's `wpautop` function which is use changes double line-breaks in the text into HTML paragraphs.This functionality provide Wordpress for better posting with default template.This function use `wpautop( $foo, $br )` Where
$foo = The text to be formatted.
$br = Preserve line breaks. When set to true, any line breaks remaining after paragraph conversion are converted to HTML <br />. Line breaks within script and style sections are not affected.
So according to theme you want to remove extra
tag that must enter below code for content and expert as use.
remove_filter( 'the_content', 'wpautop' ); 
//Use for Post Content in post detail page
remove_filter( 'the_excerpt', 'wpautop' ); 
//Use for Post Excerpt in post archive page
Use above code in your running theme's function file.If you want to know your current running theme than login to admin panel Appearance->Themes here display all themes which theme is active that display as `Active`. Find active theme function file in Wordpress root directory `wp-content/themes/THEMENAME/function.php`.

Check Current Version of Wordpress

Some times in developing phase when you want to some customization or want to add some plugin or template than it must check version comparability.so every plugin and theme provide supported Wordpress versions
Wordpress has many version till start of it and each version has some improvement better than previous.
Wordpress launched first version 0.7 on 27th May 2003. from that time to now it change more than 50 versions including beta release.currently Wordpress latest version is 4.1
For any developer or beginner who work with wordpress that it must know that version for use any where like for any customer support,error solution or configuration. Here is way for know current version of wordpress.

Using FTP Check Version

Here is first way if you know server FTP detail or you have code of all website that easy see Wordpress version as below
Open `wp-includes/version.php` file in that find `$wp_version` variable value that define Wordpress version.

Using Source Code Check Version

When you run website in browser that easy to check Wordpress version by that source as below
Press CRL+U for view source and in that find `generator` meta value that define Wordpress version.

Using Coding Check Version

If you are developer that it is easy for check version for enter simple code as below
Enter `echo get_bloginfo('version')` anywhere in header or footer file for display version.

Using Admin Panel Check Version

If you have admin details for website than see Wordpress version as below
1. Login to admin panel open `About WordPress` menu than display Wordpress version.
2. Login to admin panel in footer display current Wordpress version.

Using Add Ons Check Version

Another way is check any website version in wordpress as below
Install Browser Add Ons/Extension for Wordpress version Checker and using that you can see Wordpress version

How to Add Custom PHP Page in Wordpress





Wordpress is simple open source for create blogging website that based on PHP.Wordpress provide basic functionality for create new blog and add post in that in that add page,category and other information by using some plugin.SO in Wordpress easy to use create any blog and customize layout and design css only with Wordpress backed admin panel called `wp-admin` When you want to customize Wordpress that you must know some knowledge of it and sometimes you have some PHP file and you want to integrate it in Wordpress than it is easy for beginner.here below process for add costume PHP page in Wordpress

  1. Create new php file in your theme directory like 'demo.php' (`/wp-content/themes/themename/`).If you don't know theme name that see running theme on Wp-admin->Appearance->Themes
  2. Open PHP file and enter below code at top of page.
     <?php
     /*
     Template Name: DEMO
     */
     ?>
  3. Create New page from admin and select 'Template' that you created and save that page
See New created page display in Wordpress.Here in PHP file you can put any custom PHP code its display as you coded in fronted.
If you want to put same header as Wordpress theme than add `get_header()` function at top of page.same for footer and sidebar you can use `get_sidebar()` and `get_footer()` function.

Saturday, January 24, 2015

How to Disable Post Revision in Wordpress


Everyone know about WordPress is use for blog website creation and it's provide all features and functionality for create any type of blog.
WordPress provide `Revision` functionality also for save post revision it is like previews post operation. this functionality use when you change some changes of any post today and after that you want to receive previous post than its save as revision and you directly save post as previous post.
Revision is like undo command in our computer.

But sometimes when you confirm that your changes of any post and page are complete and you cant change anything in that than revision is not useful. therefore its must to remove that functionality because revision functionality increase database size.So it's necessary to remove that functionality to optimize database size.
Here simple way to stop post revision from post
  1. Open WP-config.php file in WordPress root directory.
  2. Enter define('WP_POST_REVISIONS', false );
  3. Save and Upload file.
Now its stop your post revision and optimize your database size.

Wednesday, January 7, 2015

Fix Establishing a Database Connection Error in WordPress


For WordPress beginner this type of error almost got and your site is not running till you install database and complete source code.
Establishing a Database Connection Error error you fetch when upload website or move website.
this type of error you got because of below mistake by you.
  • Check Database

    First check database if you local/live server than check all database table install properly or not.all WordPress database based on WP_option (WP is based on your table prefix) table so check that properly.
  • Check Config File

    In your source code of WordPress(Any version) open `wp-config.php` file in root wordpress folder in file check below lines configure with your data or not.

    define('DB_NAME', 'DBNAME');

    Here check DBNAME is your database name check your install database in MYSQL is same as below or not?

    define('DB_USER', 'UNAME');

    Here check your database user name which is given when create new DB or assign user to Databse in Local `root` is default value.

    define('DB_PASSWORD', 'PASSWORD');

    Here check your database User Password that you given when create below user.

    define('DB_HOST', 'HOST');

    Here you set host name of your MYSQL server where you put your database.most of case its `localhost`. 
After check below process your website run compactly. this method is use for any version of WordPress you use.