[SOLVED] Fix WordPress Update Requires FTP Credential

The FTP credential needed when trying to update WordPress is really annoying. However, to fix that problem is easy. It is related to file and folder ownership and permissions.

File and Folder Ownership

We need to change the file and folder ownership to www-data. Apply for both user and group otherwise it won’t work.

Usually the folder of web server directory in Linux is /var/www/yourweb.com/public_html/ we need to change the ownership on public_html itself and files and folders inside it to www-data.

$ cd /var/www/yourweb.com/
$ chown -R www-data:www-data *

File and Folder Permission

Same as above, we need to change the file and folder permissions for both public_html and files and folders inside it. But, isn’t it difficult to change those things one by one?

Therefore, we created a guide to change the file and folder permissions recursively in an easy way. For files you need to change the permission to 755 and for folders 644.

Let us know if you still have problem.

Enabling WordPress Localhost Permalink to Prevent 404 Not Found

If you have trouble to make permalink works on your localhost’s WordPress you can use these steps to make it works. But, you have to make sure that you are using Windows and Apache2.2 as your local server.

The Indication

When you point your browser to the address of your page or post that has custom permalink in it, say http://www.test.com/about/, it shows page Not Found “The requested URL /about/ was not found on this server” like this one. You may try the solution as follow.

Continue reading Enabling WordPress Localhost Permalink to Prevent 404 Not Found

Adding Google Analytics Tracking Script in WordPress Admin

How to add Google Analytics tracker in WordPress admin? It’s easy. You just need to add a few lines in your theme functions.php. This is the WordPress admin_head hook.


add_action('admin_head', 'add_google_analytics');

This is the add_google_analytics function.


function add_google_analytics(){

if(!current_user_can('level_10')):

echo "<script type='text/javascript'>

var _gaq = _gaq || [];
window.google_analytics_uacct = 'UA-XXXXXXXX-XX';
_gaq.push(['_setAccount', 'UA-XXXXXXXX-XX']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>";

endif;

}

Change UA-XXXXXXXX-XX from your Google Analytics tracking script.Oh, what is it if(!current_user_can(‘level_10’)): ? It’s a bonus for you because I think you don’t need yourself to be tracked by your analytics. So, it only tracks those who logged in not as admin.

Remember DO NOT copy paste your analytics tracking script directly. You must change the double quote (“) to single quote (‘) or you’ll get error and it will make you busy because you have to fix it through cPanel if you’re self hosted.

Creating TinyMCE Custom Styles on WordPress

For those who want their WordPress TinyMCE customized, this tutorial will be an easy guide to achieve custom styles on WordPress 3.

TinyMCE custom styles example

Script below is an example to add Inline Pre (span tag element and its class is inline-pre) and Inline Highlight (span tag element and its class is inline-highlight). Where are the class names coming from? I named them, because it’s custom styles.


function fb_change_mce_buttons($initArray) {
    $initArray['theme_advanced_buttons2']  = 'formatselect,styleselect,|,underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,wp_help';
    $initArray['style_formats'] = json_encode(array(
        array('title' => 'Inline Pre','inline'=>'span', 'classes' => 'inline-pre'),
        array('title' => 'Inline Highlight','inline'=>'span', 'classes' => 'inline-highlight'),
    ));

   return $initArray;
}

add_filter('tiny_mce_before_init', 'fb_change_mce_buttons');

The result

The Inline Pre example: This line is styled by Inline Pre.

The Inline Hightlight example: This line is styled by Inline Highlight.

Okay enough with the result samples. I think you want an explanation.

How to make your own TinyMCE custom styles

Before you fulfill your needs, you have to learn, or at least, read these documentation and other sources which paying attention to this TinyMCE customization matter.

What to prepare

You have to remember that you have to add some codes to your WordPress theme as follow:

  • Visual editor CSS
  • Theme CSS
  • Functions.php

Visual editor CSS and theme CSS

For example, you are creating Red Bold and Blue Italic styles. You have to write it in visual editor css, and theme css.

.red-bold{color: #ff0000; font-weight: bold} .red-bold{color: #0000ff; font-style: italic}

Functions.php

At the very top of this article you’ve seen the highlighted PHP script. Now you can make change:


array('title' => 'Red Bold','inline'=>'span', 'classes' => 'red-bold'),
array('title' => 'Blue Italic','inline'=>'span', 'classes' => 'blue-italic'),

So it will look like this.


function fb_change_mce_buttons($initArray) {
    $initArray['theme_advanced_buttons2']  = 'formatselect,styleselect,|,underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,wp_help';
    $initArray['style_formats'] = json_encode(array(
         array('title' => 'Red Bold','inline'=>'span', 'classes' => 'red-bold'),
         array('title' => 'Blue Italic','inline'=>'span', 'classes' => 'blue-italic'),
    ));

   return $initArray;
}

add_filter('tiny_mce_before_init', 'fb_change_mce_buttons');

Copy the script and add it to your theme functions.php. Oh if you have trouble about how to add your visual editor style your can read Function Reference/add editor style. But, it can be easily achieved by adding this line to your functions.php:


add_editor_style('visual-editor-style.css?r='.rand(1,20000));

Why is that ?=.rand(1,20000) ? It’s useful to let your style in CSS file up to date because many times browsers are caching the files and make your head dizzy and asking ‘Why the styles keep the same when I have changed and saved it!?’ Useful isn’t it?

After you’ve done with the installation please open your Add New posts. See if the style box is there.

Moving Subdomain to New Domain Name in WordPress

If you hosted another blog on your subdomain you may want to move it to new domain. In WordPress it is easy to make it done. Use these steps to make your life easier. Let’s imagine that your new domain name is kickassblog.com.

1. Put robots.txt in your new domain for example public_html/kickassblog.com/robots.txt. Fill the robots.txt with this:


User-agent: *
Disallow: /

2. Copy or move your database and WordPress files to your new domain.

3. In your wp-config.php for example public_html/kickassblog.com/wp-config.php, put these lines:


define('WP_SITEURL', 'http://www.kickassblog.com');
define('WP_HOME', 'http://www.kickassblog.com');

4. Download Velvet Blues Update Urls plugin. Activate and set it up in your WordPress admin. You’ll really need this plugin to change interlinking posts URL, images URL, and attachment URL. For example, if you have an image in your particular post that grab the image from http://blog.yourolddomain.com/wp-content/uploads/2011/02/images1.jpg, it must be changed unless it will become a broken link and the image won’t show. The Velvet Blues will do this job for you to change it to http://www.kickassblog.com/wp-content/uploads/2011/02/images1.jpg

5. Recheck your work: Check posts that have interlinking to another post. Make sure that the link points to your new domain. Check if it’s alive. Check from different IP and browsers. If you have no hesitation on it then remove robots.txt that you have created it before.

6. Redirect your blog on your subdomain by adding these lines in your .htaccess.


Redirect 301 / http://www.kickassblog.com/

Don’t for get to check your blog at old subdomain. Access its homepage and several particular posts. Make sure it’s properly makes redirection.

7. If you care about being indexed by Google you should add your site in Google Webmaster.

8. Wait and see it will take 3-7 days to get your new domain gets fully indexed by Google. Be calm, your traffic will be healed soon.

SyntaxHighlighter Evolved WordPress Plugin is Not Working

I just had SyntaxHighlighter Evolved plugin for WordPress wasn’t working, but it has been solved by me. It has made me confused for sure before I find the solution. This is the case:

Recently, I switched the theme to my own built theme. I found the SyntaxHighlighter Evolved didn’t work on the post. So, the problem appeared after I switched TwentyTen theme off.

The solution is terribly simple. Open your footer.php of your theme, then add this line.

Continue reading SyntaxHighlighter Evolved WordPress Plugin is Not Working

How to Change Permission of wp-config.php and Other Files/Directory Massively

Few days ago, I got troubled by some unethical hackers. They’re changing my directories and files permission to 777 which has ability to World-read-write-execute. That kind of permission is very dangerous. I don’t know how did they get into my cPanel File Manager. I thought it was WordPress, WordPress plugins, or WordPress theme failure, so they could inject malicious script into my public_html directory easily and freely.

I’ve ask HostGator using live chat support but one of them has said that I can’t change the permission of files or directories massively even using SSH. That’s totally wrong because few hours later after that, I found the way. Basically, you have to know how to connect to your hosting using SSH. I’ve created a tutorial how to connect HostGator using SSH.

Continue reading How to Change Permission of wp-config.php and Other Files/Directory Massively

How to Create Translation for WordPress Theme

In this tutorial you’ll learn about creating translation for WordPress theme which divided into several sections:

  • Identifying which theme has ability to be translated
  • Enable Theme To Be Translated-able
  • Create .po language file and .mo file using poEdit
  • Put .mo and .po language files in the right place
  • Tool used to edit and compile your language files

Continue reading How to Create Translation for WordPress Theme