Mostly about my amusement

Category: Software (page 3 of 22)

I should write this down

I did write this down, but I buried it in another blog post.

Sometimes you don’t want to display the featured image but you don’t want to remove the option from your theme.

This snippet in a plugin or child theme’s functions.php file will accomplish that.

add_filter( 'post_thumbnail_html', 'mh_post_image_html', 10, 3 );

function mh_post_image_html( $html, $post_id, $post_image_id ) {
if( is_single() ) {
     $html = '<!-- The featured image would be here if I chose to display it. ;) -->';
     }
return $html;
}

It doesn’t disable support for post thumbnails but replaces the code with an HTML comment if the post is_single() using the post_thumbnail_html filter. You can use other conditionals as well and even edit the HTML before returning it.

Remove shortlink URLs from comments

Or remove them from anywhere, though I’m not sure why you’d remove shortlinks from your own author’s posts.

I’ve written a small plugin that will filter your comments using preprocess_comment which is a useful filter comment data before it’s committed to your database. The other toys I used are wp_extract_urls and wp_remote_head to make http head requests to web sites.

The plugin works like this: you feed a function a URL and it gives you back a URL but with shortlinks you get the real destination. It uses wp_remote_head() to make an http HEAD request and looks for the location header.

If it finds that header then it recursively calls itself to get real destination up to 5 requests. After 5 requests the URL is replaced with the # sign. If it doesn’t find that header then the original URL is returned.

Depending on your site that can be a lot of URLs and to cache those results I create transients for those URLs. The next time in a 12 hour window that URL is tested then WordPress will pull the data from the transient.

I’ve never used transients and I’m not sure this is a good idea or not. But if you need to eliminate shortlinks then this plugin might do it. Also this parses all URLs in the post or the comment and that’s probably not necessary. A simple check can be put in to see if the URL is on a list of shortlink providers and ignore all the rest.

You can download the plugin from this Gist page.

Once you’ve downloaded it save it to your wp-content/plugins directory as short-links-begone.php and activate the plugin in your WordPress dashboard. This plugin will not change any post data or old comments. It will modify new comments when they are submitted.

No more @import for me

Well, at least not for current WordPress child themes.

I like child themes and always recommend that people use them instead of modifying any WordPress theme directly. Using a child theme makes your changes belong to you and they won’t get erased when the original theme gets updated.

I’ve told people to use something like this in their child theme’s style.css file.

/*
Theme Name: Sorbet Child theme for Mostly Harmless
Theme URI: https://blog.dembowski.net/
Description: Child theme for the Sorbet theme
Version: 0.1
Author: Jan Dembowski
Author URI: https://blog.dembowski.net/
Template: sorbet
*/

@import url("../sorbet/style.css");

/* Start your custom CSS after this line */

See that @import line? That had previously been required if you wanted to inherit the parent theme’s CSS. At the moment my child theme does not have that @import anymore and instead I’ve created a functions.php file with these lines in it.

<?php

function mh_sorbet_child_style() {
        wp_enqueue_style( 'sorbet-parent-style', get_template_directory_uri() . '/style.css' );
        // wp_enqueue_style( 'sorbet-child-style', get_stylesheet_uri() );
}

add_action( 'wp_enqueue_scripts', 'mh_sorbet_child_style' , 5 );

Which really is a more WordPress way to do it. I added a function mh_sorbet_child_style() where I first queue up the parent theme’s style.css and then queue up the child theme.

Notice how I commented out the second line? The parent theme already queues up the current theme’s style.css file and in my case that is sorbet-child/style.css. In my child theme I do not need to queue it a second time as it’s not necessary.

But I do want to ensure that the parent theme is queued up earlier than the child theme CSS. That’s why I add the wp_enqueue_scripts with a priority of 5 instead of the default 10. That should always load the parent CSS first. If the theme does not queue up it’s style.css that way then I would un-comment out that line.

Just as before, any new CSS will go into my child theme’s style.css file.

 

OK, no more Xmarks for me

I like the idea behind Xmarks but there seems to be something I am doing that’s just not working.

Here’s what I’ve done.

  1. Installed Xmarks on all of my browsers. For Internet Explorer this meant a small system tray app.
  2. Made one set of bookmarks the Master To Rule all of My Bookmarks™. I did that once and confirmed that Xmarks has those bookmarks via the My Xmarks page. Neat page BTW.
  3. Synchronized all of my browsers. The first time I selected “the download and erase bookmarks on this browser” option.
  4. Bookmarks are synchronized! Sweet.

A few days later I started losing whole sections of my bookmarks. Not so sweet. Fortunately Xmarks has a great revision system and I was able to roll back to the set I wanted. Repeatedly. Sometimes more than once an hour.

I think the culprit is Chrome but I just couldn’t get the darn thing to behave. I’m sure Xmarks is not at fault, It’s just that one of my browsers never attended kindergarten and doesn’t know how to share with the other kids.

I’m back to manually synchronizing my bookmarks which isn’t a big deal as I don’t add to them that frequently. For Firefox I’m using Mozilla Sync which has developed into a nice option from years ago. For that browser it just works and also synchronized my add-ons, preferences, etc. For Chrome the bookmarks are shared using the Great Google Data Collection Experiment™.

This may have been why I stopped using this software in the first place. Meh, back to sorta syncing my bookmarks at least in Firefox and Chrome.

I may have broken my Feedburner feed

After I converted my WordPress install to 100% SSL I noticed that my own feeds in Tiny Tiny RSS were not updating. Years ago I forwarded my RSS feeds to Feedburner and 301 redirects from https://blog.dembowski.net/feed/ https wasn’t working.

I can’t even remember why I used Feedburner. I’m pretty sure I turned it on in a moment of “What’s that button do? *Monkey pushes button*”.

I’ll keep testing but eventually I’ll disengage Feedburner and just use https://blog.dembowski.net/feed/ instead.

Edit: This work around seems to fix it.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} blog.dembowski.net [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/feed/$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{QUERY_STRING} !^feed=rss2$
RewriteRule ^(.*)$ https://blog.dembowski.net/$1 [R=301,L]
</IfModule>

The part starting at line 5 is where I added conditions so that the SSL 301 redirect will be ignored.

Why not use SSL and be done with it?

On the Internet there has been talk about Google and SSL based web sites. Apparently you may get a small boost if you switch to https. I myself doubt that (I’m jaded that way) and the additional SSL math will slow down busy sites a little. But I don’t get enough traffic to care really and I do like to play. This seems easy enough to do.

I Like Server Based Solutions and I Cannot Lie

I use WordPress multisite and on my web server I have a valid SSL certificate installed. I’m already using Apache’s mod_substitute to modify https://blog.dembowski.net/ to https: before it get’s sent to the browser for my SSL site.

Why not switch to SSL and be done with it? I could have used a tool to change all the WordPress database references to https but I’m running multisite and I wanted to be a little more site specific so I added this to my .htaccess file above the WordPress part but below the “Get Lost, I don’t like you” part.


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} blog.dembowski.net [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://blog.dembowski.net/$1 [R=301,L]
</IfModule>

So far it hasn’t broken anything and is limited to my this one and not the other sites. I’ll keep an eye on it but there’s no reason for me not to leave it that way. I like server based solutions but for other people a HTTPS plugin may be an easier way to go.

The only downside is that I will need to maintain my SSL certificate but I plan to do that anyway.

So this means I wear a tin foil hat?

Not really but it does mean in most cases people visiting my site will get the traffic encrypted between my site and their browsers.

*Adjusts Tin Foil Hat™ and skips conversation about  SSL transactions and man in the middle interception*

It’s more a concern that someone will have some key logger or other hack installed on their machine.

Sniffing unencrypted data on the Internet is easy. Doing so for encrypted SSL traffic is more difficult. It would require the Bad Guy or Spook to have access to the private certificate issued by the certificate authority. Or exploit a server bug and harvest the SSL private certificate from the web server. That would never happen right…?

If your interested in how it all works then start with this Wikipedia article on TLS. This Digicert article is good too and may be easier reading. In the meanwhile anyone coming to my site will get redirected to the SSL based version.

That was a short walk and I installed Xmarks

When I switched the laptop back to Firefox I bemoaned the lack of being able to synchronize my browser’s bookmarks with each of my other devices. That was on the list for why I used Chrome in the first place:

  1. Shared passwords
  2. Shared history
  3. Shared bookmarks
  4. Participating in the massive data collection experiment known as The Great Google™ BOW BEFORE THE DATA COLLECTION MONSTER!

That last one always made me tighten my tin foil hat just a little.

Shared passwords are easy with 1Password. I set it up to synchronize with Dropbox, picked a reasonably complex password that I can remember and just go. I have my passwords on Windows, Mac, my Android phone and the iPad. It doesn’t work with Linux as far as I know but I always have my phone with me and it’s all good.

Using Xmarks covers the other items and it works well.

I use it to synchronize my bookmarks and history but I turned off the other add-on items like site info. This shouldn’t surprise me as I’d used this tool before and I still can’t recall why I stopped using it (though it might have been because it shutdown for a while).

It works in the background and with those other features disabled it’s really transparent and unobtrusive. That’s good software design: it performs it’s job and gets out of your way. Cool.

I could setup my own server to sync with but I don’t think my bookmarks are really that telling. That doesn’t mean there is not a lot of good social engineering potential in my bookmark data: it’s just that I’m already tracked one way or another by the Great Google Monster™ so Xmarks isn’t high on my list to be concerned about.

Featured image photo by B Rosen

Cross platform browser bookmarks?

Chrome on my laptop drains the battery dry so I’ve installed the current Firefox and went through some quick installations and all is right in the world. I installed the following:

  1. Firefox – Duh.
  2. 1Password4 extension
  3. Greasemonkey

It struck me that my favorite tools have cross platform equivalents.

  1. Chrome
  2. 1Password4 extension
  3. Tampermonkey

But what I am lacking is a tool to easily sync my browser bookmarks. Yes, I can easily export and import them but I’m lazy and would prefer a tool that works across all browsers.

I may need to give Xmarks another look. I forgot why but there was something about it years ago that turned me off.

I prefer using apps that work the same between platforms. I use Postbox for that reason (it’s also a cool mail app) even though it doesn’t have any data sync exactly. I’m using the same mailbox in both so the experience is the same even when I accidentally send a private email to a mail distribution list. I make the same mistakes on both versions.

The same goes with the 1Password application and I was thrilled when the Windows version was updated. The 1Password app is a great example of cross platform utility. The experience between Windows and Mac just works and it works consistently.

I’ll need to do some digging for a bookmark solution that I like.

Featured image Photo by Titanas

Favorite new WordPress 3.9 feature

Copying and pasting from Microsoft Word directly into the Visual Editor is my new favorite thing in 3.9 beta. I just tried it on Lily’s store WordPress site and it worked alright. This is a fortunate side effect of 3.9 getting a new version of TinyMCE.

I know, that sounds anti-climatic even a little mundane given the great enhancements that 3.9 will be delivering. But I occasionally (once a month) have this conversation.

Them: How can I copy this Word document into WordPress?

Me: First select the text and paste that into notepad. I like notepad++ myself.

Me: Then you take the text you just copied into notepad select and copy it into the Visual Editor. Again.

Me: Make sure you copy from notepad. Bad things will happen if you paste that into the Visual Editor directly from Word.

Me: Then you apply the styling such as bold, underline, etc. To that text. For titles I like to use the <h3> tag myself.

Me: No, that layout thing you did in Word won’t work.

Me: Images? If you use the Snipping Tool then you can save that image to your hard disk.

Me: Once you’ve done that, upload that into the media library.

Me: Then you can insert it into the WordPress post. The image I mean, I usually go with centered and no link.

Them: Zzzzzz Wha-? What we’re we talking about??

I myself don’t like the idea of users creating content for WordPress outside of WordPress but I’m told I’m special. Apparently “regular” users (yes I’m doing the “air quotes”) such as my wife and some siblings use Word that way.

Lily creates flyers for wine tastings once a week. Right now she has to wait for me to create the event on the WordPress site (thank you Modern Tribe! that’s a great plugin) then cross post it to the company Facebook page. If I can show her how to just paste the content into WordPress to create the event then she can deliver the post sooner.

Also that means I’ll have one less thing to do each week.

Next I have got to test out dragging images into the Visual Editor to upload them that way. That’s got to improve “regular” users workflow too.

Let’s play a game called SERP

On the support forums occasionally (OK today) someone will ask that a post be edited to remove a link or company name for SEO reasons. Unless there’s a good reason for that (and SEO isn’t) then it just isn’t done. There are millions of posts on those forums; can you imagine if a small percentage of members asked for posts to be edited that way?

It’s not always necessary to edit The Interwebz

I am not a web front end developer. I don’t do “SEO”, I don’t at this time have any advertisements on my site. I post to my self-hosted WordPress blog for my own amusement and occasionally the amusement of my friends.

But just for giggles, let’s do a search on Google for my name. I wonder what comes up?

seo-games-jan-dembowski

Huh. That’s weird.

The first hit is my Twitter page, followed by my Make/Support author page, a Polish biologist then a general who both died before I was born (no relation). Then there’s some images (hey, 3 of those are me!) and then my WordPress site. Ah, there’s my Flickr page. I was worried about that not being there.

There is nothing on that search engine results page pointing to the WordPress forums. That’s a shame. I’ve got *looks WOW* 10,772 posts in the forums. That’s not necessarily a lot by the way.

How did that happen?

Again I am not into “SEO” and I haven’t done anything to impact that SERP. I even had to look up what SERP meant to make sure I’m using the term correctly.

But my guess is that the results happened that way because those links are pertinent and each of those links have content that is updated. That’s all there is to it.

  • I tweet everyday non-stop so it’s no wonder that popped up as the first hit.
  • I post to make/support at least once a week so there’s that.
  • Links 3 and 4 are cool and I like that my name is notable (even if the original spelling was Dębowski, ę is pronounced /ɛm/, w is a v sound, look it up).

The important thing is that I produce content and that’s why when someone looks up my name you get sites that I actually update.

So “SEO” magic isn’t real?

There are people who advertise and I assume make a living on SEO work and I am sure they know what they are doing.

If I had a site that I was selling something then I may be concerned that my actual site is 6th down from the top (skipping the images). If I were selling something then perhaps I’d use an SEO plugin. I’d also update my actual site more frequently.

Even without my doing anything special a search for my name shows the links that I expected to see.

My advice to people who want links removed from the forums or anywhere remains the same: if you don’t like your search engine results then change them. Produce original content on your own site. That’s really all there is to it.