Archive for Web Development

The non-breakable Dash / Hyphen

In HTML you may find that the dash / hyphen character is a breakable character and if you are attempting to create a region where line breaking is not desired you may need a non-breakable space character.

Here it is: ‑

Removing everything BUT Images in a WordPress Post

A while back I wrote an article on Removing Images from a WordPress Post. Sebastian asked an interesting question; he wanted to remove everything but the images. This is actually pretty straightforward; here is how you do it:

 
.
.
.
<?php
           $beforeEachImage = "<div>";
           $afterEachImage = "</div>";
           preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
           for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
                 echo $beforeEachImage . $matches[1][$i] . $afterEachImage;
           }
?>
.
.
.

Keep in mind this code needs to be in the WordPress Loop and you can control what is around each image using the variables beforeEachImage and afterEachImage above.

Browser.php updated to v1.6

Version 1.6 of Browser.php has been released with a lot of updates: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

Opera 10’s User Agent

For those of you who detect Opera 10’s user agent, the Opera team has provide some “fun” for all of us. In my Browser project I started getting feedback that it was broken. At the 10,000′ level, it was defintely broken because the Browser project was returning version 9.8 for Opera version 10.

This is because the Opera dev team decided to leave the version 9.8 user agent string the same and tack on version 10 to end of the string. You can read more about it on their blog.

For those of you using my Browser project have no fear; the new version (1.6+) handles the oddity!

Moving a WordPress Install from one Domain (A) to another Domain (B)

From time to time I had have to move one installation of WordPress from one domain (let’s call it domain A) to a new domain (let’s call it domain B). Because WordPress embeds the domain all over the data schema (not faulting; simply disclosing) you have to make a lot of dB changes for the updated site location to function. Here is the quick and dirty way to move the data:

UPDATE wp_posts SET post_content = REPLACE(post_content,"[OLD_DOMAIN]","[NEW_DOMAIN]");
UPDATE wp_posts SET guid = REPLACE(guid,"[OLD_DOMAIN]","[NEW_DOMAIN]");
UPDATE wp_options SET option_value = REPLACE(option_value,"[OLD_DOMAIN]","[NEW_DOMAIN]");
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value,"[OLD_DOMAIN]","[NEW_DOMAIN]");

Finally, for the final bit of trickery if you are using Advanced Caching on the site there is a great place where the localized PATH is hard coded. Edit your new and updated path on file advanced-cache.php

vi wp-content/advanced-cache.php

Browser.php updated to v1.5

In the Browser.php project John pointed out (in the comments) a terrible typo in the source. I imagine no one has encountered this before as it only effects v1 or v1.5 of Internet Explorer.

Typo updated and version 1.5 of Browser.php released: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

Removing Images in a WordPress Post (Revisited)

A while back I wrote a semi-popular post on removing images from a WordPress post — today I am revisiting it. The original solution used the_content() and the output buffer to remove the images out of the post. Now that I have used WordPress a bit longer and candidly had to use the solution again and thought “what was I thinking” I thought I would share the cleaner solution:

.
.
.
<?php echo preg_replace('/<img[^>]+./','',get_the_content()); ?>
.
.
.

Browser.php updated to v1.4

I released v1.4 of the Browser.php project today to address a few features suggested by readers. This new release adds support for GoogleBot, Yahoo! Slurp, and the W3C Validator.

Check out version 1.4: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

Browser.php updated to v1.3

Based on a comment on the Browser.php page I added support for the iPod today. I opted to place both the iPhone and iPod as browsers even though they are likely using the same instance of Safari. Additionally I added support for the iPod and iPhone as platforms. Thanks for the comments; enjoy!

Updated Browser.php to version 1.2

The browser detection project in php (Browser.php) has been updated to version 1.2 based on suggestions I received in the comments. The new version is available for download in the project pages.

Thanks to all those who have emailed and commented on the script.