I just upgraded this blog to 3.5 on a whim as I was writing tonight and although the new Media Manager seems kinda cool, I hate that they removed the max embed size from the Settings menu and are now apparently just deriving the content dimensions for embeds from your theme directly. I mean, it sounds cool in theory, except that WordPress somehow came up with a 640 pixel width out of my theme, whereas I wanted the limit set to 575 px … I’m guessing that maybe it doesn’t take margins into account or something?

Anyways, in the meantime luckily I found a quick, little function that overrides the oEmbed settings and lets you set your own instead – here’s what I ended up throwing into my theme’s functions.php file to get things looking back to normal again…

function example_custom_oembed_dimensions($html, $url, $args) {
 
// Set the width of the video
 $width_pattern = "/width=\"[0-9]*\"/";
 $html = preg_replace($width_pattern, "width='575'", $html);
 
// Now return the updated markup
 return $html;
 
} // end example_custom_oembed_dimensions
add_filter('embed_oembed_html', 'example_custom_oembed_dimensions', 10, 3); 

WordPress Santa Smiley!

December 13, 2012 12:22am
Tagged with:

So you noticed that cute, little guy at the end of my last post, did ya?

:santa:

He was actually pretty easy to add to the standard smilies catalog in WordPress!

  1. Just save the image above and upload to /wp-includes/images/smilies/
  2. Then add a new line to the end of the array in /wp-includes/functions.php (assuming WordPress 3.0+; I believe you want /wp-includes/vars.php for earlier versions)
':|' => 'icon_neutral.gif',
';)' => 'icon_wink.gif',
':!:' => 'icon_exclaim.gif',
':?:' => 'icon_question.gif',
':santa:' => 'icon_santa.gif',

Now I should note that if you happen to be using a smilies plugin like I realized that I am here, you’ll likely need to do step #2 in the config file for that plugin instead. I’m using Smilies Themer, so the file I ended up updating was /wp-content/plugins/smilies-themer/default/package-config.php.

You’ll also probably notice that this particular icon is just a tad taller than the standard WordPress smilies, so it tends to throw off line heights if you’re using a default. I thought about scaling it down a bit to try to put it in line with the others, but you can just as easily put it on its own line and it saves you a trip to the Photoshop! Nonetheless, it seemed like a fun, little way to spruce up your WordPress blog around the holidays – enjoy…

:santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa: :santa:

Open Graph + WordPress != Fun Times

October 7, 2012 11:22pm
Tagged with:

So today I spent pretty much all day setting up a feed from my pumpkin site into its new Facebook page.

It shouldn’t have taken all day – it was really only supposed to take a couple of hours, by my calculations, but apparently Facebook’s Open Graph protocol is a gigantic pain in the ass. Or the new WordPress Facebook plugin is a pain in the ass. I’m honestly still not really sure which…

In the past I’ve always done this by using a Facebook app that uses the site’s RSS feed, but it always seemed inefficient, there was the inevitable lag time from when I posted a new article to when the service actually checked for updates, and I’m not really a huge fan of relying on lots of 3rd party hosted services anyways, so it made sense when I started seeing push to Facebook-style plugins for WordPress popping up that eventually I’d move to using something like that, too. And since pumpkin didn’t even have a page of its own yet, this seemed like a good opportunity to experiment and find the best one to eventually roll out to all of the other sites as well.

Boy, did I not know what I was getting myself into!

Part of my problem was that a few months ago I started experimenting with an Open Graph plugin that simply adds all of the OG tags to your pages – it doesn’t do any actual publishing, but at least it puts the tags out there because otherwise when somebody shares a link to one of your articles on Facebook, the site has to crawl the page to figure out what to show for the title, description, thumbnail image, etc…, and the results of that crawl aren’t always that great. Or at least that was my experience, so I installed that plugin and was more or less happy with the results that I was getting.

Fast forward to today when I needed to figure out the publishing part. My first stop was the official Facebook plugin for WordPress because it was new and shiny and seemed to have some neat features like mentions and messages that other plugins didn’t.

Unfortunately, it also has a couple of ugly bugs that I personally decided I couldn’t work around – namely, it wasn’t selecting the correct image for the post’s thumbnail, it was doubling up the description, also somehow it was including HTML markup in one of the copies of the text in the description. Eventually I learned that apparently I had conflicts from two different plugins both inserting duplicate Open Graph tags into my pages, but even after disabling the first plugin, I was still getting the goofy double results with no end in sight. And it was really bizarre – posts would appear fine if I copy & pasted the link into Facebook, but when I had the plugin post as if I was publishing a new article, I’d get the bad results.

I honestly fought with this for a while and even considered trying to migrate some of the features that I liked from the other plugin into this one, but after probably a good 6 hours I finally decided that enough was enough and I’d need to move on to something else – a pain because I really wanted to use the official plugin, but I still had other writing to do, too! 😯

So next I moved on to a plugin called Simple Facebook Connect, which was just about perfect except for one kinda dumb, little detail – for some reason, the link used to post to Facebook wasn’t the properly formatted permalink, but instead the original WordPress link (i.e. /?p=12345 instead of /blog/post-name/). That bugged me and I found a recent post from the developer citing that he had no plans to change it anytime soon, so I didn’t get too attached and kept looking…

FINALLY I settled on this older plugin called Facebook Page Publish and after some quick testing, I concluded that it not only did it format everything the way that I was looking for, but it also somehow posts them as links rather than as application posts, so they’ve got the little embedded box as if I had actually just copy & pasted links into the page like I first started, which I kinda like. The settings that I’m using look something like this:

I probably should’ve also taken some screenshots along the way to show just how anal I was about getting the formatting just right, and I’m honestly still not 100% satisfied with my results because I read that Facebook likes to tweak Open Graph a lot, so there’s a good chance that my posts could stop working at just about anytime, but at least for right now, it seems to be working ok.  😕

One other tool that I’ll share that helped me a lot to really pinpoint where my problems were – Facebook’s debug tool essentially takes any URL that you feed it and spits back the Open Graph results that it reads off the page, whether through analyzing the page or even just reading the tags from your header directly. I guess this is also supposed to flush out the cache for a given URL, which was a suspect for me at one point when I couldn’t seem to get the post thumbnails even remotely close to being accurate!

Ultimately, big wall of text translates to about 10 hours total fighting with Facebook and WordPress … but who knows, maybe your site will be different and the tags will automatically populate correctly based on your own formatting styles the first time around!!! I hear the official plugin works better if you use featured images in your posts instead of embedded images like I do with this site…

Woof – I don’t even want to think about it anymore. Onward, to something else … anything else! 😯

Comment Spam for Dummies

September 27, 2012 11:49pm
Tagged with:

I’m very thankful that Akismet does such an amazing job of blocking comment spam on all of my WordPress sites – I really don’t even have to think about it, but every now and then out of morbid curiosity I’ll skim through one of my spam queues just to see what kind of stuff is getting stopped anyways.

A quick note to whoever runs the Easiest Automatic Blog Commenter – you might want to change the name that your app posts under to something just a little more discrete … maybe! 🙂

Hey, look – LiveJournal comments!

August 28, 2012 8:39pm
Tagged with:

Frankly, I’m just as surprised as you are…

I hadn’t exactly given up on getting my comments imported from LiveJournal after migrating the rest of the blog over last fall, but at the same time, it was kind of out of my hands unless I was willing to go under the hood myself…

…which I was actually thinking about doing, even though I really have no idea how that API even works…

…but luckily, I didn’t have to because out of the blue, I saw an update to the import plugin yesterday so I decided to give it another try, and low and behold, it actually started doing stuff when it got to the comment import portion!

Mind you, the importer ran and ran for a long time, which I know that it technically anticipates with a warning at the top for those who have lots of comments (mine allegedly has 802), but apparently part of it was because somehow I ended up importing a ton of duplicates that I later had to go back in and wipe out. Sorry … I didn’t save the exact query, but I used something along the lines of this to weed out the couple of thousand extras that piled up on a handful of posts.

(You also need to refresh the comment count afterwards because that’s actually stored at the post level, fyi…)

So anyways, I’m definitely happy that this is finally completely done … I honestly don’t get a ton of comments or anything, but having migrated everything else over I kinda felt bad that the comment section hadn’t followed with the rest of my earlier posts as originally intended. Now this is truly a full copy of my original blog that I started way back in 2003, so it makes me feel better to know that if LJ eventually does go completely under one day, I’ll still have a snapshot in its entirety of my early years of blogging! 😉

If you’ve been having issues on importing comments from LiveJournal to WordPress for the same reason, it might be worth updating to the latest version of the plugin (0.5, as of now) and giving it another shot. Of course, be sure to backup your database before kicking it off, but I didn’t get any duplication with the posts that I’d already pulled in – just some weirdness with duplicate comments that took maybe an hour or so afterwards to resolve.

It’s taking me a little while to get through because it’s 2 hours long, but I’ve really been enjoying this interview that PandoDaily did last month with WordPress founder Matt Mullenweg. He talks about all sorts of topics including the “corporate culture” at Automattic, why he believes in the open source ecosystem, and even a little about his own passion for BBQ…

Some really intriguing points, and I especially loved to hear him talk about how the right directions to take with WordPress as a whole have not always been the ones that would simply make the most for investors in the near future. I love that when you listen to Matt talk about the future of blogging, he talks about a marketplace dominated by open source software and not just his own … it really shows that he cares about giving back to the online community, and I say this not simply because I’ve been able to use his software for free to drive my own publishing interests over the last five years! 😉

So if there’s one thing moving my blog from LiveJournal over to WordPress has reminded me, it’s just how much I absolutely, positively love WordPress!

This is something that I’ve been planning to do on and off for quite a while now, although it kept slipping off the radar due to other priorities.  Well, last weekend for whatever reason I was feeling particularly unmotivated with whatever I was supposed to be working on, so instead I decided to start digging into this new little project.  I found a theme that I liked … well, technically a couple of them that I ended up mashing together to get what you see here today … and after a few hours of hammering away at the initial theme setup, the question came – just how ugly was importing all of my posts from LJ actually going to be???

I was ready for the absolute worst (i.e. copying and pasting them one by one into new posts ad nauseam), but instead it turns out I was both lucky and happy to find that not only does a script already exist to pull in content directly using LJ’s API, it even already has hooks built into the WordPress core!  It was literally a 5-minute job – click to install the actual plugin to do the heavy lifting, enter my username and password, and then wait while it churned through some 2,000 blog posts spanning the last eight years of my life!

The only problem that’s still outstanding is for some reason the importer isn’t pulling the comments down after it finishes with the posts themselves – instead, it just says that I don’t have any comments and then finishes, whereas apparently I have about 800 comments!  So I still need to keep an eye on that – I already found where a WordPress.com user is reporting the same problem recently, so hopefully they’ll fix it sooner than later and we’ll officially be in business.

In the meantime, next steps are to finish polishing up the interface a little more, although so far I’m already very happy with the aesthetics, then for the blog side of things I do actually still have to go through each and every post manually – both because I want to refine my tags and also need to tag a good 80% of the older posts before I started using them, and also to address a few small issues where Flash videos, etc… didn’t actually get embedded like they should’ve.

So mostly small stuff, but still time consuming – once I can get everything sorted out so I know what all to look for, I’ll just pick 50 or so a night and slowly start pouring through them until they’re all done.  In the end, I do think that it’s going to make for a better site, and besides, being the nostalgic doof that I am, I never really mind pouring back through old posts that I wrote years ago all that much anyways… 🙂

So in summary, thus far probably my easiest redesign I’ve done in a long while!  I still have one more that’s on the docket to knock out later on this month before Thanksgiving, and I can only hope that it goes as smoothly as this one did.

So today’s big project was something that ended up taking a whole lot longer than I had expected, but at least I can say that I’m definitely happy with the results. Up until the latest one, I’ve been using Flickr to host the photos for the write-ups that I occasionally do for our Wednesday night LFR games, however I actually hit the photo cap for free accounts (200 photos) a while ago and in the meantime have just accepted the fact that as I added newer posts, the photo sets from the older ones were disappearing. I wasn’t crazy about the idea, and I almost considered just paying the $18 for a while to side-step the issue, but ultimately I knew that eventually one day I needed to suck it up and migrate all of the galleries back to my own server because a) it’s silly to pay Flickr when I already have a monthly hosting bill anyways, and b) hosting them myself allows me to do a lot of cool things that I simply can’t do via another service.

Anyways, several nights of uploading photos, updating posts, and tweaking code later, everything has been moved over and seems to be running smoothly. I’m using the NextGEN Gallery plugin for WordPress – the same one that I’m using for the other big project I’ve been randomly musing about – and all in all I think I’m really starting to like it as a photo gallery for WordPress sites. My one beef is that it doesn’t handle comments on a photo by photo basis, which is more of an issue for the other site than this one, but in the same vein I’ve already spent years struggling with Gallery2 and even though it’s technically a more robust gallery system, integration with other sites is just atrocious and I don’t think I’ve ever come across a site using it in a way other than the regular, blocky templates that come stock with it.

In fact, I’m currently running Gallery2 for the photos on scottandsara.info and I’ll probably end up moving those into NextGEN eventually too because it just seems too clunky for what it does these days…

That said, here’s the final product for the D&D site:


I’ll do a separate post here in a little bit about the technical hurdles that I faced with this one because there is some customization taking place under the NextGEN hood, but overall I really like how it allows me to highlight the photos from my LFR Adventure Logs because there are times when I think I enjoy going back and just flipping through the pictures more than reading the actual posts! Bottom line is, after over 300 photos across 24 separate games, it was time for something a little fancier than Flickr sets and I think NextGEN does the job nicely, if I do say so myself! 🙂

Conquering Regular Expressions

May 23, 2011 11:08pm
Tagged with:

So in between battling puppy pee, I’ve also been fighting with regular expressions for the better part of the evening. To summarize, I hate regular expressions. I just don’t get the logic, never have, and just when I think something makes sense, I’m told that I forgot like eight different escape characters or special circumstances or whatever and I feel like I’m back at square one.

With that said, after my last geeky code post of this nature, I decided that I want to get in the habit that when I fight with something long enough, I at least post about it online, both to vent and also to share in case someone else encounters something similar in the future!

Anyways, the scenario is this – working in PHP with WordPress, writing a custom category template for a new site I’ve been building. In this case, I needed to be able to pull the first image tag out of a post so that essentially I could create a category view that simply showed POST TITLE/DATE/ETC, IMAGE, MORE LINK TO VIEW ENTIRE POST.

Quickly, the caveats:

  1. I know that there are plug-ins to do this, however using code directly in the template is far more efficient because this will really only affect a fraction of the posts.
  2. Those plug-ins basically just parse out the tags, which won’t work for me anyways because I’m using NextGen Gallery for my images, meaning that the syntax stored in post is a shortcode like this – [singlepic id=123 w=550 h=413 float=center].

I fought with regular expressions for hours upon hours, but finally managed to come up with this:

(searching for this tag)
[singlepic id=123 w=550 h=413 float=center]

preg_match_all ('/(^\\[.*?\\])/is', get_the_content(), $matches);
$image = $matches[0]; $image = $image[0];
echo do_shortcode($image);

Basically it just looks for a tag in brackets at the very beginning of the post, which is my default format, however also meaning that it won’t get caught on anything if for whatever reason I end up using additional tags later on in the post. The first function does the actual search through the post content and throws the results into an array ($matches), with the second line extracting the tag out to a single variable and the final line executing it as a WordPress shortcode.

I’m still not entirely sure why I have to do line #2 twice – I guess between the preg_match_all() function and the data, it ends up as an array within an array, but after literally four hours of staring at this stupid thing, what you see above is officially the point where I said, “It works – good enough!”

WordPress Bug Talk

May 9, 2011 6:48pm
Tagged with:

I know that this one is going to get a little more technical than most, but after battling with WordPress over something that in retrospect just seems incredibly inane, I feel the need to pronounce my victory in a public forum such as this…

So on one of the sites that I’m currently revamping (and hoping to officially launch in May), I’m doing a lot with photo galleries embedded in pages … probably not using pages exactly the way that was intended, but it seems to get the job done so I’m not going to complain. Anyways, the trouble started when I wanted to introduce a related posts plugin that also accommodates pages – the plugin technically works great, however one tiny detail in the format that I wanted for the output really just managed to throw me for a loop.

Basically, despite my pages being nested – sometimes several levels deep – in the related posts output, I always wanted to see the top-level mentioned instead of a page’s immediate parent. For example:

Photo Galleries —> Food —> Watermelon

becomes

  • (Photo Galleries) Watermelon

not

  • (Food) Watermelon

So the trick here is that you can’t simply look to a page’s parent, you need to loop through all of its parents’ parents until you get back to the top. The good news is, there’s actually a function already in WordPress to do exactly this. The bad news is, it’s broken!

I discovered this the hard way after feeling triumphant one night about solving my problem, then getting up the next day to find that it was only sometimes working. Most of the time I would get the correct “grandparent,” but for one page in particular I got back a null value instead, despite seeing the hierarchy plain as day through the main admin interface. From there I tore apart the database tables looking for an incorrectly populated relationship, started from scratch with the function itself, and even tried deleting and rebuilding the page, thinking that it might be a problem from when the page was originally generated.

Nothing, until another day at random I happened across this page

Apparently it’s a caching problem that was found almost two years ago, however obviously being not a very high priority just never got addressed. Fortunately in my case, though, a workable fix was found at the end of that thread – the basic solution was to run a function to clear that specific post out of the cache. Admittedly not knowing a ton about how WordPress’ cache works and not wanting to break something by constantly clearing the cache for every single post and page, I ended up doing something like this…

if ($post->post_parent)	{
   if (!get_post_ancestors($post->ID)) { wp_cache_delete($post->ID, 'posts'); }
   $ancestors=get_post_ancestors($post->ID);
   ... }

At least this way the deletion only runs if the ancestry is already broken for a particular page. This is definitely the first time that I’ve ever had to dig this deep to root out a problem in WordPress … usually it’s a problem with my coding, not theirs! So anyways, that’s my story and all is now well in the universe – just had to share in case someone else one day stumbles across that same problem with get_post_ancestors() and they still haven’t fixed the bug yet…

Happy coding!

© 1999 - 2018 Comedic-Genius Media, All Rights Reserved.