WordPress 4.6 crashed my site

Fatal error: Cannot redeclare the_post_thumbnail_caption() (previously declared in ….

This error occurs because the_post_thumbnail_caption is a new function in WordPress 4.6.  However, people have been using this function for over 5 years now.  How?  Stackoverflow and other WordPress forums are flooded with questions asking how they can print out the thumbnail caption.  Since this wasn’t a built-in function before, the answer was to make your own function which was appropriately named the_post_thumbnail_caption.

Many theme authors, myself included, are now guilty of simply copy-pasting this function without adding their own theme prefix.  To avoid errors like this, functions within a theme should be prefixed with something unique to the theme like “mymonkeytheme_the_post_thumbnail_caption”.

If you have this error, contact your theme author and ask them to fix the theme.


Posted in Coding Tagged with: ,

Git Copy

This may be obvious to the git experts, but I am not that.  There also may be a better way to do this, but again, not a git expert.

I have a git repo set up on WPEngine, but they only allow the whole server to be a repo, not just a single plugin.  This was a problem since the whole server directory was not in my current repo.  So it was either make a new repo which was basically a copy of my current repo but a different folder structure or keep on using SFTP.  I decided to make a new duplicate repo.  The problem (which i also had with SFTP) was finding the files that changed and pushing them to the server.  This is both error-prone and slow.  I found a script that could copy all changed files from the last commit into my WPEngine deploy directory and also discovered a way to do this automatically when pushing from my main repo.

Create/Save this script in .git/hooks/pre-push file.  This would be in the main git repo I work in.  This copies all changed files to the WPEngine deployment repo.


MOST_RECENT=$(git log -n 1 –pretty=format:’%h’)
PREV=$(git log –skip=1 -n 1 –pretty=format:’%h’)

echo “Coping to $TARGET”
for i in $(git diff –name-only $MOST_RECENT $PREV)
# First create the target directory, if it doesn’t exist.
mkdir -p “$TARGET/$(dirname $i)”
# Then copy over the file.
cp “$i” “$TARGET/$i”
exit 0

Thanks to the following articles about pre-push hooks and how to get the files between commits.



Posted in Server Stuff

WordPress the_title filter changed in nav menus

I haven’t had time to look into the exact reason or the exact version this changed, but as of at least WordPress version 4.5.2 the nav menu uses the_title multiple times for one item.

For example if your theme used something like this:

function menu_title_filter( $title ) {
return $title . ' | ';
add_filter( 'the_title', 'menu_title_filter' );

It would have one ” | ” after each menu title in previous versions, but in WordPress 4.5 ish it would show two ” | “.  Again, haven’t looked at the exact cause that changes this, but the solution is to check if the item you’re looking at is a nav_menu_item:

function menu_title_filter( $title, $id ) {
$item = get_post( $id );
if ( $item->post_type != 'nav_menu_item') return $title;
return $title . ' | ';
add_filter( 'the_title', 'menu_title_filter', 10, 2 );

Posted in Coding Tagged with:

Relative positioning of table rows and row groups is now supported. This site may need to be updated because it may depend on this feature having no effect.

Firefox displayed this warning in the Firebug console.  This warning indicates an absolutely positioned does not consider a table element relatively positioned so it may not appear as expected.  A better explanation is here:


and solution to fix is here:


Posted in Coding Tagged with: , ,

Draggable Icon in Font Awesome

This is weird.  Font Awesome has a ton of fonts, but no draggable icon.  Issue #816 is on github shows much love for this added feature, open since 2013.

A workaround for this suggested by abanctelchevrel:

/* \f142 is ellipsis-v */
/* \202F is thin unbreakable space */
.fa.fa-grip:before {
content: "\f142 \202F \f142 \202F \f142";
.fa.fa-grip-large:before {
content: "\f142 \202F \f142 \202F \f142 \202F \f142 \202F \f142 \202F \f142 \202F \f142";

fa-grip-large : <i class=”fa fa-grip-large fa-rotate-90″></i>
fa-grip <i class=”fa fa-grip”></i>

Posted in Coding Tagged with:

Link from Google Redirecting

After years of not having a client get hacked, I got 2 in a few weeks.  One client (client A) has a WordPress site which I developed the theme on.  Another client (client B) was brand new, no WordPress.  Client A’s site was redirecting to a porn site whenever a visitor went through a link from Google.  Client B’s site was redirecting to a 404 page (a php file was not found).  Both sites were fine when visiting the direct link.

I found malicious code in Client A’s .htaccess file redirecting anyone visiting from google, bing, or any of the major search engines.  I found and removed the PHP files that were not supposed to be on the site.

Client B’s site was clean as a whistle. Nothing suspicious in the htaccess file and no mysterious php files.  Needed to contact the host about this one.

In searching for more information on how the attackers may have gotten in, I came across this worrisome forum.  Both clients are on GoDaddy so this is probably the issue they both had:


Posted in Coding, Server Stuff Tagged with: , , ,

Speed up WP_Query

In WordPress, when a query does not need paging and you only want a limited amount of results, like the last 5 posts, set the ‘no_found_rows’ parameter to true.  This prevents WordPress from doing additional work in counting the total matched rows, thus speeding up your query.

This is already built into get_posts, but not WP_Query.


$last_5_query = WP_Query( array( ‘no_found_rows’=> true, ‘posts_per_page’=>5 ) );

Posted in Coding Tagged with: , ,

Disable Responsive Images in WordPress

In WordPress 4.4 images are displayed with the srcset attribute.  This attribute allows the browser to select alternative images for best viewing.  Sometimes though this may not be wanted as the image being displayed is the only image you want to show for all users.

To not have any srcset images, use the following:

add_filter( ‘wp_calculate_image_srcset_meta’, ‘__return_null’ );

For other filters new to WordPress 4.4, you can visit the blog post:

Responsive Images in WordPress 4.4


One user had a problem with the images in the srcset not having the https protocol and causing security warnings.  This stack overflow post resolves that:



Posted in Coding Tagged with:

Escape strings for use in JavaScript

When using parameters from the URL, it should always be sanitized before using it in your javascript.

Using jQuery you can easily do:

var safeString = $(“<span></span>”).text(unsafeString).html();

Using plain javascript:

var entityMap = {
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': '&quot;',
    "'": '&#39;',
    "/": '&#x2F;'

  function escapeHtml(string) {
    return String(string).replace(/[&<>"'\/]/g, function (s) {
      return entityMap[s];

The stackoverflow discussion can be found here:  http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery


Posted in Coding Tagged with: , ,

Left Sidebar Under Content


Having a left sidebar move under the content in a responsive design needs a bit more thinking.  You can’t just do float left width 100% or display block and let the sidebar fall to the next line.


When the browser width is narrow, use display:table-footer-group for the sidebar, display:table-header-group for the content, and display:table for the parent container.

See more:


Posted in Coding Tagged with: ,