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:

https://wordpress.org/support/topic/malware-redirect-hacks-specific-question-regarding-vulnerabilities?replies=12

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.

Example:

$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:

http://wordpress.stackexchange.com/questions/211375/how-do-i-disable-responsive-images-in-wp-4-4

 

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

Problem

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.

Solution

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:

http://www.iandevlin.com/blog/2013/06/css/css-stacking-with-display-table

Posted in Coding Tagged with: ,

Run WP-Cron with no visitors

Got a website with noone visits or simply a website that is private but still need WP-Cron to be run?  no problem, you have 2 easy options.

1) Setup a free account with set https://www.setcronjob.com ( i like them better because they enable email notifications on the free account).   Create a cron job to visit wp-cron.php on your domain.

2) set up a scheduled task or cron job on your computer.  Mac OS X and Windows PC.  Problem with this though is your computer needs to be on with internet access, and if you ever buy another computer (and don’t turn your current one on) this job will never run:

https://developer.wordpress.org/plugins/cron/hooking-into-the-system-task-scheduler/

Posted in Coding Tagged with:

Macbook and the read only SD Card

Until recently I thought my SD cards from my camera were write protected by the camera formatting.  Apparently it’s just my macbook pro being flaky.  The macbook has some flaw where even when switching off the manual lock switch, SD cards are still readonly.  The solution is to set the switch in the middle between lock and unlocked.  You’ll need to try it a few times to get the position just right, but once you do the card is writable.
Sources:

http://www.jackenhack.com/sd-card-readonly-macbook-pro-card-reader-solved/

https://discussions.apple.com/thread/2166984?start=0&tstart=0

Posted in Random Thoughts

Order Non-hierarchical Custom Post Types

Non-hierarchical post types are like regular posts which normally do not have a menu_order attribute.  Hierarchical post type are like pages which allows a parent/child and is normally ordered by the menu_order attribute.  What if you have a custom post type that shouldn’t have a parent/child, but you still want to order it by something other than the post date?  This code does the trick on the admin side.

https://wordpress.org/support/topic/sorting-by-menu_order-in-admin-screen-on-non-hierarchical-custom-post-types

Posted in Coding Tagged with: ,

Moving Email Hosts

Transferring where your email is hosted can be tricky.  When moving from one host to another email is usually stored with the hosting plan.  If you have bad luck with hosting companies you may want to consider hosting your email on Zoho or Google Apps so you don’t have to go through this lengthy process every time you move.

Here are the steps to move email hosting:

  1. Backup your mail on your email client.  Usually it backs up to a .pst file.
  2. Set your incoming mail server to the IP address of the mail server.  This is so your mail client looks at your old server even after you change hosts.
    1. To do this, find the setting for your incoming mail server
    2. Do a DNS lookup to get the IP address.
    3. Paste the IP address into the incoming mail server setting.
  3. Set up email addresses on the new hosting account.
  4. Set up another account in your email client with the new host settings.
  5. Import your old mail into your new account by following your mail client’s instructions on importing.
  6. Now you should get mail from both new and old servers.
  7. After a week or so you can remove your old account and cancel the old hosting.  Be sure to transfer messages from the old account before deleting your old account.
Posted in Server Stuff Tagged with: