Category Archives: WordPress

All things WordPress on Linux. I don’t do WP on Windows as there is no point. If you have a licenced Windows server install Hyoer-V and run up a virtual linux system for apps like WordPress. Its a much more robust process than trying to make Windows do things it was never designed to do.

Turning off WordPress redirects index.php to index.html on Cpanel Apache

I spent a bit of time today trying to research why Apache on Cpanel insisted on redirecting from index.php when it was entered as an explicit URL to the default index.html page in the website home directory.

As it turned out, while I am searching for “cpanel apache redirects” I should have been asking “Why does WordPress redirect…” and that change of question led me to this WordPress forum thread that addressed the actual issue.

Now normally I would not repeat the information here, but just in case that link disappears, I do want to be able to get to it again, so here it is.

The issue actually is not Apache or Cpanel driven, but is an issue with WordPress and the way that it redirects all requests to the home page for the site. Hence despite me trying to access index.php, WordPress was redirecting to index.html, and that prevented me from seeing the new WP site.

Ultimately the purpose of this was to allow for WordPress to be installed alongside an existing page based site and deploy for final user acceptance before switching off the old site and moving to WordPress as the new site.

The trick is simply a manually installed plugin that can be removed after final commissioning to production.

1. Open your site with an FTP program or SSH depending on you preference

2. Navigate to yoursite_folder/wp-content/plugins/

3. Create a new folder for the plugin – call it disable-canonical-redirects – or dcr for short

4. Change to that folder

5. Create a new index.php file and include (copy and paste or re-type) this PHP code into that file:

<?php
/*
Plugin Name: Disable Canonical URL Redirection
Description: Disables the "Canonical URL Redirect" features of WordPress 2.3 and above.
Version: 1.0
Author: Mark Jaquith
Author URI: http://markjaquith.com/
*/

remove_filter('template_redirect', 'redirect_canonical');
?>

5. Visit your WordPress Admin backend and activate this new plugin

6. All is now good to go and access index.html by default or index.php for WordPress explicitly.

Many thanks to Mark and others in that discussion thread.

 

Nextgen Gallery WordPress nggtags template caption option

I have a slightly older version of NGG because I have modded it and have yet to transfer those mods to the latest version. But I just made another minor change that I wanted to document before I forget what I did.

Using the

no images were found

  works well for showing the images from the gallery that are tagged as an automated gallery creation.

But I wanted to get the captions displayed as well like the syntax for the standard gallery by id display

no images were found

.  So I needed to add the ” template=caption” as an option for the nggtags shortcode.

Edit /wp-content/plugins/nextgen-gallery/nggfunctions.php

Around line 867 should start the function into which I inserted the $template value (with relevant comma’s etc.) at 3 places as highlighted with the new text.

function nggShowGalleryTags($taglist, $template = '') {

// $_GET from wp_query
$pid    = get_query_var('pid');
$pageid = get_query_var('pageid');

// get now the related images
$picturelist = nggTags::find_images_for_tags($taglist , 'ASC');

// look for ImageBrowser if we have a $_GET('pid')
if ( $pageid == get_the_ID() || !is_home() )
if (!empty( $pid ))  {
$out = nggCreateImageBrowser( $picturelist, $template);
return $out;
}

// go on if not empty
if ( empty($picturelist) )
return;

// show gallery
if ( is_array($picturelist) )
$out = nggCreateGallery($picturelist, false, $template);

$out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
return $out;
}

That sorts out the function that is called from the  /wp-content/plugins/nextgen-gallery/lib/shortcodes.php

Around line 114 there is a string evaluation test process that we change to look for a second option referenced as template= etc..  shown in the highlighted line.


if ( stristr( $content, '[tags' )) {
$search = "@(?:<p>)*s*[tagss*=s*(.*?)s*]s*(?:</p>)*@i";
if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {

foreach ($matches as $match) {
$replace = "

no images were found

}" template="{$match[2]}"]"; $content = str_replace ($match[0], $replace, $content); } } }

Finally around line 273 there is the call to the nggShowGalleryTags in the show_tags function. Insert a new line for $template as a parameter and to the output option.


function show_tags( $atts ) {

extract(shortcode_atts(array(
'gallery'       => '',
'template'  => '',
'album'         => ''
), $atts ));

if ( !empty($album) )
$out = nggShowAlbumTags($album);
else
$out = nggShowGalleryTags($gallery, $template);

return $out;
}

Now the nggtags option that will create a custom gallery from Tagged images can optionally include the image caption as well.

 

 

WordPress wp_list_pages includes Home link for no reason

Well, it’s never for ‘no reason’ but it can be hard to find.

I have been working with the free download ColorWay theme By InkThemes.com and while I like the theme it was annoying me that when I used the wp_list_pages function to get a list of child pages (which I logged earlier this year), it kept adding the Home page to the list as if it were a child of the page.

As it turns out after much tracking of the source of the issue, I find that the Colorway theme includes an add_filter function to insert the Home link at the top of the wp_list_pages function to build the main menu. I tracked this down to this file:

wp-contentthemescolorwayfunctionsinkthemes-functions.php

What I found was that the add_filter was being applied for the specific purpose and was then left as a persistent process.

at around line 46

wp_list_pages('title_li=&show_home=1&sort_column=menu_order');

and at around Line 63

add_filter('wp_list_pages, 'inkthemes_new_nav_menu_items');

Line 46 was inside a function which builds the main menu:

function inkthemes_nav_fallback() {
	?>
    <div id="menu">
        <ul class="ddsmoothmenu">
            <?php
               wp_list_pages('title_li=&show_home=1&sort_column=menu_order');
            ?>
        </ul>
    </div>
    <?php
}

Which I modified to basically place the add_filter as a part of this function only and added a remove_filter at the end to put it back to normal.

function inkthemes_nav_fallback() {
        // 20121103 thowden copied from line 63 to place relevant to this function only
        add_filter('wp_list_pages', 'inkthemes_new_nav_menu_items');
	?>
    <div id="menu">
        <ul class="ddsmoothmenu">
            <?php
			wp_list_pages('title_li=&show_home=1&sort_column=menu_order');
            ?>
        </ul>
    </div>
    <?php
     // 20121103 thowden added to reset the standard wp_list_pages function
     remove_filter('wp_list_pages', 'inkthemes_new_nav_menu_items');
}

So now the InkThemes menu will still work but will not perpetuate the wp_list_pages function change.

But, the body of the page list is still a problem and that is because line 63 as shown above is NOT in a function and is always applied. So the simple solution is to delete it, or comment it out of the code.

// 20121103 thowden to remove Home from list pages
//add_filter('wp_list_pages', 'inkthemes_new_nav_menu_items');

and all is well with the world again…

WordPress FTP prompt for Upgrade or Update

There are a lot of posts around about the FTP prompt when preparing an upgrade and all (almost all) reference the same information which is to enter specific settings in the wp-config.php file for the FTP site, username, & password.

Alternatively, I prefer this option which allows the admin user with the correct permissions to avoid the FTP aspect altogether.

In the same wp-config.php file in the WordPress root, around line 10 it will look like this:

 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //

Just insert a few lines and add the 3 DEFINE lines as per the example below:

 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */
define('FS_METHOD', 'direct');
define( 'FS_CHMOD_DIR', 0775 );  // change these settings to match your apache account
define( 'FS_CHMOD_FILE', 0664 );  // change these settings to match your apache account

// ** MySQL settings - You can get this info from your web host ** //

The key is the CHMOD entries. In my case the cpanel / WHM server is configured for the apache account to act as the group controller of the files. So to upload and modify files in the Worpress directory it needs write permissions as group not owner.