(07) 3040 6690

Posts Tagged ‘wordpress’

Add Images to Your WordPress Summary Feed

Monday, August 31st, 2009

wordpressThere are different reasons to use excerpts instead of full content in your rss feeds, Such as discouraging sploggers from stealing your content, and encouraging feed subscribers to visit your site. A drawback of this though is that WordPress by default only uses the first 55 words of your post in an excerpt minus any image or other media files you may have included in your post. One way around this is to enter your own custom excerpt into the excerpt field of your post editor while in HTML mode. Another method which I’m now using automatically adds the first image in your post (or a default image you specify if there is no image in your post) to your rss content, involves a function I found at Live Experience . Simply add the following code to your wp-includes/functions.php file:

function get_first_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
//Defines a default image
$first_img ="http://yoursite.com/image.png";
}
return $first_img;
}

Then open up wp-includes/feed-rss2.php or the file name that corresponds to which ever feed format you’re using, next find each instance of the following line of code

and append the following to the front of it:

' ?>

That’s all there is to it, if you’ve done everything right you should now automatically have images in your feeds, if you use a them which uses excerpts I’m sure you can think of at least one other way to use this function as well ;).

Update: The steps above involve editing some of the WordPress core files. The main problem with this is that you lose your changes whenever you update WordPress. A slightly modified and easier way is to simply place the following code into your themes functions.php file.

function get_first_image($content) {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
//Defines a default image
$first_img ="http://yoursite.com/image.png";
}
return '
'.$content;
}
add_filter('the_excerpt_rss', 'get_first_image');
?>

If you should receive a php headers error, check to make sure there are no spaces or empty lines between any of the php code blocks in your functions.php file

Redirect a WordPress Post to its Permalink

Sunday, August 30th, 2009
grey-l

WordPress

I realize the title of this post may sound a little redundant, but I’ve noticed something peculiar in WordPress, it seems that it will automatically redirect a page if you change the page name (aka slug) but wont bother with anything else in the URL. Case in point I recently published a blog but forgot to set the category name, and my WordPress URLs are set to include the category name as follows http://domain.com/category/slug/ so after I updated the post category I realized the post was still accessible using the old category name in the URL without redirecting, as well as with the new category name, I then noticed I could pretty much type in any category name as long as the slug was right the post would still load, this may be fine or even good from a purely functional stand point but not something you want from an SEO perspective, but luckily you can get the correct permalink and make sure the post redirects there using a couple of built in WordPress functions. Below is the code I placed in the head of my template which makes sure all post direct to the proper permalink.

//Get the URL used to request the current page.
$pageURL = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
//Get the WordPress permalink.
$pageLink = get_permalink();
//Make sure the page is a single post
if(is_single()){
//Check if the request URL is the same as the WordPress permalink.
if($pageURL!=$pageLink){
//If the URL and permalink are not the same redirect with a 301(permanent) or 302(temporary) redirect
wp_redirect($pageLink, 301);
exit;
}
}
?>

Wardell Design WordCamp Chicago Giveaway

Sunday, March 29th, 2009

wordcampchicago

Hi readers! Here goes my first contest ever.  This one will require a Twitter account to enter.

To enter all you need to do is post a tweet about this contest on Twitter, then post a link to the tweet in the comment section on this blog post,  along with the other standard comment info so I can contact you if you win of course. One lucky winner will be chosen at random on May 1st to receive a free ticket to the two day WordCamp Chicago event in downtown Chicago on June 6-7 2009 .

The rules are as follows:

  • Contest open to U.S. residents only.
  • Must be 18 years or older to enter.
  • One entry per person.
  • Winner must provide their own transportation to and from the event.
  • Entry deadline is 04/30/2009 at 11:59pm U.S. central standard time.

Good Luck!  And feel free to follow me on Twitter as well @wardelldesign

WordCamp Chicago 2009

Saturday, January 17th, 2009

June 6th : 8th, 2009 WordCamp Chicago at Chicago, IL

WordCamp is a conference type of event that focuses squarely on everything WordPress. Everyone from casual end users all the way up to core developers show up to these events. These events are usually highlighted by speeches or keynotes by various people.

WordCamp Chicago 2009

WordCamp Chicago 2009

Update: Win a free ticket to WordCamp Chicago here.

© Wardell Design 2015
Entries (RSS) and Comments (RSS).