Restore WordPress database on a new server

[this post will be properly edited]

I was creating the new database and WordPress would tell me to install the site.

Solution: dropped the database and created it from ‘mysql’ prompt.

user$ mysql -u root -p’yourpassword’ -h localhost
mysql> create database your_database_name;
mysql> exit
user$ mysql -u root -p’yourpassword’ -h localhost your_database_name

Permalinks on WordPress (amazon EC2)

Motivation: in my particular case I moved a WordPress site from Bluehost to amazon’s EC2. Permalinks were not working.
Solution: I had to modify the override option from my httpd service.

  1. Go to /etc/httpd/conf and edit httpd.conf
    1
    2
    3
    4
    
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
  2. Change also AllowOverride if it is set to None.
    1
    2
    3
    4
    5
    
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
        AllowOverride All
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
        AllowOverride All
  3. I you haven’t created it yet, place in the root directory of your wordpress installation a .htaccess file with the following contents:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
     
    # END WordPress
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

Source: this post.

remove_filter function in WordPress

Motivation: In a specific website I am using the simplex theme. If one tries to place a static page as home instead of the blog, simplex keeps showing the Home page.
Solution: as you can see, people have already reported this. But in the current version of the theme the line is introduced in functions.php and functions are not really overridden, they can be just replaced.
In the codex it is described how to remove actions and filters but it turned out that the solution didn’t work for me. As usually, it was really easy but cost me a bit to figure out:

1
2
3
4
5
6
function unhook_simplex_function() {
    if(has_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' )){
        remove_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' );
    }
}
add_action('init','unhook_simplex_function');
function unhook_simplex_function() {
    if(has_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' )){
        remove_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' );
    }
}
add_action('init','unhook_simplex_function');

Instead of calling the remove_filter function directly in my functions.php I just added an action that calls the function that will remove the filter from the ‘init’.

WordPress in Spanish

Motivation: it’s pretty simple. I just wanted to create a WordPress site in Spanish.
Solution: download the file from the source specified below. Extract the file es_ES.mo and place it in /wp-content/languages/. Finally, change the file wp-config.php in the root directory to point to Spanish language: define ('WPLANG', 'es_ES');
Source: http://es.wordpress.org

Orphan next post arrow in Safari and Chrome

Motivation: in the single post page, the arrow that points to the next post appears one line below the ‘Next’ text in Safari and Chrome browsers.
Solution: I don’t know if this is a ‘good’ way to solve it or if I should report it somewhere, but as a quick fix I’ve edited my child style.css file adding the following:

1
2
3
4
5
6
#nav-single .nav-next {    
    float:right;
}
#nav-single .nav-previous {
    float:left;
}  
#nav-single .nav-next {    
    float:right;
}
#nav-single .nav-previous {
    float:left;
}  

WP-reCAPTCHA: javascript error in pages without submit button

[UPDATE]: it seems that the problemis solved since version 3.1.5 (but I’m not certain if this is version 3.1.5 or since 3.1.6. Anyway, you don’t need to read this post if you are using one of those versions or above.

Motivation: I’m using the WP-reCAPTCHA plugin and there is a javascript error in every page where I didn’t include any post comment box.
Solution: Found here. But I’m copying the solution here anyway:
“In the recaptcha.php page, there’s a function called “save_comment_script”. In the middle of it is a block of code that currently looks like this”

<script type="text/javascript">
var sub = document.getElementById('submit');
document.getElementById('recaptcha-submit-btn-area').appendChild (sub);
document.getElementById('submit').tabIndex = 6;
if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') {
	document.getElementById('comment').value = _recaptcha_wordpress_savedcomment;
}
document.getElementById('recaptcha_table').style.direction = 'ltr';
</script>

Change that code to look like this:

<script type="text/javascript">
if(document.getElementById('submit') != null)
{
	var sub = document.getElementById('submit');
	document.getElementById('recaptcha-submit-btn-area').appendChild (sub);
	document.getElementById('submit').tabIndex = 6;
	if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') {
		document.getElementById('comment').value = _recaptcha_wordpress_savedcomment;
	}
	document.getElementById('recaptcha_table').style.direction = 'ltr';
}
</script>

Code Snippet

Note: this post is deprecated, I moved to another plugin, see this new post.

Motivation: I want to publish code into my posts. I’m not really motivated to search or code anything so I’ll go for a plugin this time.

Solution: I found this plugin called “WordPress Code Snippet” which for me it’s okay. Maybe in the future I’ll search for another solution but right now it does the trick.

Two blogs in the same page

Motivation: I want to show 2 blogs in my WordPress site. A quick search on the web reveals that apparently you must install each blog separately, but I don’t want to do so. In fact I don’t need two different blogs, I just want to split posts in two different pages (by category).

Solution: the solution I found consists of using the original posts site for one of the blogs and an extra page (with a specific template) to show the other blog pots. Separation is done by category applied to each post.

  1. Create a Page of Posts template. I’m using a child theme of Twenty Eleven so I just create a pageofposts.phpfile with the code below. Then change the category you want to filter for this blog (blog2).
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    
    <?php
    /*
    Template Name: Page Of Posts
    */
     
    // if you are not using this in a child of Twenty Eleven, you need to replicate the html structure of your own theme.
     
    get_header(); ?>
    <div id="primary">
    <div id="content" role="main">
     
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
        'category_name' => 'antiquarianism, championship', // Change these category SLUGS to suit your use.
        'paged' => $paged
    );
    query_posts($args);
    if( have_posts() ) :?>
     
    <?php twentyeleven_content_nav( 'nav-above' );?>
     
    <?php while ( have_posts() ) : the_post(); ?>
     
    <?php get_template_part( 'content', get_post_format() ); ?>
     
    <?php endwhile; ?>
     
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
     
    <?php else : ?>
    <article id="post-0" class="post no-results not-found">
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    </header><!-- .entry-header -->
     
    <div class="entry-content">
    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    </div>
    </article>
     
    <?php endif; ?>
     
    </div>
    </div>
     
    <?php get_footer();
    <?php
    /*
    Template Name: Page Of Posts
    */
    
    // if you are not using this in a child of Twenty Eleven, you need to replicate the html structure of your own theme.
    
    get_header(); ?>
    <div id="primary">
    <div id="content" role="main">
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => 'antiquarianism, championship', // Change these category SLUGS to suit your use.
    	'paged' => $paged
    );
    query_posts($args);
    if( have_posts() ) :?>
    
    <?php twentyeleven_content_nav( 'nav-above' );?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <?php get_template_part( 'content', get_post_format() ); ?>
    
    <?php endwhile; ?>
    
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
    
    <?php else : ?>
    <article id="post-0" class="post no-results not-found">
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    </header><!-- .entry-header -->
    
    <div class="entry-content">
    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    </div>
    </article>
    
    <?php endif; ?>
    
    </div>
    </div>
    
    <?php get_footer();

    UPDATE: I finally just filtered it in the index.php file. I'm keeping the code above just in case you want to go for that approach, but what I have really done is to copy the idex.php into my child theme. As the post pages is the home, I have added the following code that omits all the posts from programming category:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $id_cat_prog = get_cat_ID('programming');
        $args= array(
            'cat' => '-'.$id_cat_prog, 
            'paged' => $paged
        ); 
        query_posts($args);
    ?>
    <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $id_cat_prog = get_cat_ID('programming');
        $args= array(
            'cat' => '-'.$id_cat_prog, 
            'paged' => $paged
        ); 
        query_posts($args);
    ?>
  2.  
  3. Getting category id. You can just check it from your configuration, but I want to obtain my category id from a category name, so I'm using the function:
     
    1
    
    <?php get_cat_ID( $cat_name ) ?>
    <?php get_cat_ID( $cat_name ) ?>
  4.  
  5. Excluding posts from blog 2 to appear into my feed. I don't want my feed to be updated with posts I place in blog 2. Here I found a list of different WordPress feeds so in my feed address I can filter excluding the category of my second blog posts. By the way, in my case I placed a RSS icon in the menu bar so I manually added the post filter from WP Dashbord (Appearance --> Menus, and edit link from custom option.
     
  6. Once you are in the post view if you click on the 'next' or 'previous' post button by default all the posts (doesn't matter to which category they belong) will appear. But I want only posts of 'my current blog' to appear. To solve this I'm using the next_post_link function to tell that I want to filter next or previous posts by category. You only have to edit a few lines in single.php. Here you have an example:
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    <?php
    $cat_prog = get_cat_ID('programming');
    $cat_pers = get_cat_ID('personal');
    $cat_wp = get_cat_ID('wordpress');
    $cat_bh = get_cat_ID('bluehost');
    if (in_category($cat_prog)) {
        $cat_filter = $cat_pers;
    }
    elseif (in_category($cat_pers)){
        $cat_filter = $cat_prog.','.$cat_wp.','.$cat_bh;
    } 
    ?>      
    <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ),FALSE,$cat_filter); ?></span>
    <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ),FALSE,$cat_filter ); ?></span>
    <?php
    $cat_prog = get_cat_ID('programming');
    $cat_pers = get_cat_ID('personal');
    $cat_wp = get_cat_ID('wordpress');
    $cat_bh = get_cat_ID('bluehost');
    if (in_category($cat_prog)) {
        $cat_filter = $cat_pers;
    }
    elseif (in_category($cat_pers)){
        $cat_filter = $cat_prog.','.$cat_wp.','.$cat_bh;
    } 
    ?>      
    <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ),FALSE,$cat_filter); ?></span>
    <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ),FALSE,$cat_filter ); ?></span>
  7.  
  8. I want to show a different Archives Page for each blog. In one of them I want to show posts by Year and Month. I used the Collapsing Archives plugin. Of course, I don't want posts from the second blog to be listed here. In order to configure the posts I will show in Archives and their style I created an archives.php file in my child theme. Then you only have to create a new page and apply the new template. Be careful: this plugin also takes into account the 'tags' of the post in order to do the filtering, it treats those tags as if they where post categories. Thus you'll have to exclude them in the options:
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    <?php
    /*
    Template Name: Archives
    */
    get_header(); ?>
     
    <div id="container">
    <div id="content" role="main">
    <?php the_post(); ?>
    <h1 class="entry-title"><?php the_title(); ?></h1>
    <h2>Archives by Year & Month</h2>
    <?php
    if( function_exists('collapsArch') ) {
      collapsArch('animate=1&inExcludeCat=exclude&inExcludeCats=programming,wordpress,bluehost,code,snippet,widget'); // in my case 'code','snippet' and 'widget' are tags and not categories
    } else {
        wp_get_archives();
    }
    ?>
    </div><!-- #content -->
    </div><!-- #container -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    <?php
    /*
    Template Name: Archives
    */
    get_header(); ?>
    
    <div id="container">
    <div id="content" role="main">
    <?php the_post(); ?>
    <h1 class="entry-title"><?php the_title(); ?></h1>
    <h2>Archives by Year & Month</h2>
    <?php
    if( function_exists('collapsArch') ) {
      collapsArch('animate=1&inExcludeCat=exclude&inExcludeCats=programming,wordpress,bluehost,code,snippet,widget'); // in my case 'code','snippet' and 'widget' are tags and not categories
    } else {
        wp_get_archives();
    }
    ?>
    </div><!-- #content -->
    </div><!-- #container -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
     
  9. Finally I wanted to show my programming posts divided by category. Tried to use Collapsing Categories plugin but it won't expand properly. I posted on WordPress forum and I'm currently waiting for any hints on this.And just as a mental note if I finally solve this point: by using this plugin I found another error which is solved here.