<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Engineer &#187; hack</title>
	<atom:link href="http://wpengineer.com/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Change the Search-URL of WordPress</title>
		<link>http://wpengineer.com/2258/change-the-search-url-of-wordpress/</link>
		<comments>http://wpengineer.com/2258/change-the-search-url-of-wordpress/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 09:16:39 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2258</guid>
		<description><![CDATA[With WordPress it is easy to activate readable URLs. Only the search page is not affected by the setting yet, it comes with the syntax ?s as default. But there is a solution to change the URL as you wish. The following example shows that even if you have permalinks activated, that the URL for [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress it is easy to activate readable URLs. Only the search page is not affected by the setting yet, it comes with the syntax ?s as default. But there is a solution to change the URL as you wish.</p>
<p>The following example shows that even if you have permalinks activated, that the URL for the two searchterms <em>wordpress</em> and <em>consulting</em> looks like this: <code>bueltge.de/?s=wordpress+consulting&#038;submit=Search</code>. With a little function, which communicates with the redirect, you can adjust the URL. In my case the URL with the two searchterms look like this with the following function: <code>bueltge.de/search/wordpress+consulting</code>.<br />
<span id="more-2258"></span><br />
Within WP-function <code>wp_redirect</code> I set the output, that the term <em>search</em> will be added to the <em>home-url</em> of your installation and added by the searchterms. There are many possibilities to adjust the URL.</p>
<pre>
function fb_change_search_url_rewrite() {
	if ( is_search() &amp;&amp; ! empty( $_GET&#091;&#039;s&#039;&#093; ) ) {
		wp_redirect( home_url( &quot;/search/&quot; ) . urlencode( get_query_var( &#039;s&#039; ) ) );
		exit();
	}
}
add_action( &#039;template_redirect&#039;, &#039;fb_change_search_url_rewrite&#039; );
</pre>
<p>I would recommend to put the function in a Plugin or in the <code>functions.php</code> of your theme. Any other or better ideas to accomplish this? Please let us know in the comment area.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2258/change-the-search-url-of-wordpress/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Load A Stylesheet Only If Use Gallery</title>
		<link>http://wpengineer.com/1949/load-a-stylesheet-only-if-use-gallery/</link>
		<comments>http://wpengineer.com/1949/load-a-stylesheet-only-if-use-gallery/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 13:43:34 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1949</guid>
		<description><![CDATA[In relation to the better Gallery it is actually not necessary to load the stylesheet if there is no gallery, so it is worth it to check in advance whether the gallery will be used in the post or not. For this you have to parse the post which can be done in two ways. [...]]]></description>
			<content:encoded><![CDATA[<p>In relation to the <a better href="http://wpengineer.com/a-solution-for-the-wordpress-gallery/">better Gallery </a> it is actually not necessary to load the stylesheet if there is no gallery, so it is worth it to check in advance whether the gallery will be used in the post or not. For this you have to parse the post which can be done in two ways.<br />
<span id="more-1949"></span><br />
The classic solution is to parse the content and seek the short code, classic PHP <a href="http://php.net/manual/en/function.strstr.php"><code>strstr</code></a>. Depending on the result it loads the stylesheet.<br />
<code>if ( strstr( $post->post_content, '[gallery' ) )</code>.<br />
This obviously takes time and performance, what you really like to avoid. Thus, it is better if you can parse the post in advance. In this context, there is a <a href="http://wordpress.org/support/topic/350167#post-1344676">tread in the forum of WordPress</a>, which contains a very nice solution by <a href="http://w-shadow.com/">WhiteShadow</a> which you can use to load the stylesheet.</p>
<pre lang="php">
// onyl css, when post has a gallery
function gallery_stylesheet( $posts ) {
	if ( empty( $posts ) )
		return $posts;

	$found = false;

	foreach ($posts as $post) {
		if ( stripos( $post-&gt;post_content, &#039;&#091;gallery&#039; ) )
			$found = TRUE;
			break;
		}

	if ( $found )
		wp_enqueue_style( &#039;gallery-stylesheet&#039;, get_bloginfo(&#039;stylesheet_directory&#039;) . &#039;/gallery.css&#039;, FALSE, FALSE, &#039;screen&#039; );

	return $posts;
}
add_action( &#039;the_posts&#039;, &#039;gallery_stylesheet&#039; );
</pre>
<p>You can also use this to load scripts,</p>
<pre lang="php">
// onyl js, when post has a gallery
function my_script( $posts ) {
	if ( empty( $posts ) )
		return $posts;

	$found = false;

	foreach ($posts as $post) {
		if ( stripos( $post-&gt;post_content, &#039;&#091;my-script&#039; ) )
			$found = TRUE;
			break;
		}

	if ( $found )
		wp_enqueue_script( &#039;my-script&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/js/my_script.js&#039;, FALSE, FALSE, TRUE );

	return $posts;
}
add_action(&#039;the_posts&#039;, &#039;my_script&#039;);
</pre>
<p>For more information, to include JavaScript and CSS files, there is <a href="http://wpengineer.com/use-javascript-libraries-in-and-of-wordpress/">another post</a> about this topic.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1949/load-a-stylesheet-only-if-use-gallery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Exclude A Category From Turn Off Comments Automatically</title>
		<link>http://wpengineer.com/1944/exclude-category-from-turnoff-comments-automatically/</link>
		<comments>http://wpengineer.com/1944/exclude-category-from-turnoff-comments-automatically/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 06:43:27 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[turn off]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1944</guid>
		<description><![CDATA[Thanks to our post New Ideas For 2010? Now It’s Your Turn! we got an email form one of our loyal sponsors Chris Coyier. Hey WP Engineer folks! I have a little issue I'm trying to resolve on CSS-Tricks, regarding comments. In my discussion settings, I have it set to automatically turn off comments on [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to our post <a href="http://wpengineer.com/new-ideas-for-2010-now-its-your-turn/">New Ideas For 2010? Now It’s Your Turn!</a> we got an email form one of our loyal sponsors <a href="http://css-tricks.com/">Chris Coyier</a>.<br />
<span id="more-1944"></span></p>
<blockquote><p>Hey WP Engineer folks!</p>
<p>I have a little issue I'm trying to resolve on <a href="http://css-tricks.com">CSS-Tricks</a>, regarding comments. In my discussion settings, I have it set to automatically turn off comments on everything after one-month. However, on certain things, specifically the snippets pages which all share a common page template, I want the comments to be left on forever.<br />
This seems like the job for some fancy functions.php work that you guys are the masters at <img src='http://wpengineer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p></blockquote>
<p>Ok Chris, here is our solution (copy the code in your functions.php and change the $cat values):</p>
<pre lang="php">
/**
 * Close comments on an old post.  Hooked to comments_open and pings_open.
 * small modifications on the default functions of WordPress
 *
 * @param bool $open Comments open or closed
 * @param int $post_id Post ID
 * @param int $cat Category ID (cat_ID), set &#039;&#039; or empty for all categories
 * @param int $days_old Days to close comments, set &#039;&#039; for use value from settings
 * @return bool $open
 */
function wpe_close_comments_for_old_post( $open, $post_id, $cat = array(1, 4), $days_old = &#039;&#039; ) {
	if ( !$open )
		return $open;

	if ( in_category($cat) )
		return $open;

	if ( &#039;&#039; === $days_old )
		$days_old = (int) get_option(&#039;close_comments_days_old&#039;);

	if ( !$days_old )
		return $open;

	$post = get_post($post_id);

	if ( time() - strtotime( $post-&gt;post_date_gmt ) &gt; ( $days_old * 24 * 60 * 60 ) )
		return false;

	return $open;
}
add_filter( &#039;comments_open&#039;, &#039;wpe_close_comments_for_old_post&#039;, 10, 2 );
add_filter( &#039;pings_open&#039;,    &#039;wpe_close_comments_for_old_post&#039;, 10, 2 );
</pre>
<p>Thanks Chris for your idea and please send us an email if you also have a nice idea how we could make WordPress even better.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1944/exclude-category-from-turnoff-comments-automatically/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>A Solution For The WordPress Gallery</title>
		<link>http://wpengineer.com/1802/a-solution-for-the-wordpress-gallery/</link>
		<comments>http://wpengineer.com/1802/a-solution-for-the-wordpress-gallery/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 14:25:11 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1802</guid>
		<description><![CDATA[There are things in WordPress, I do not like. This includes the gallery. Not that the idea behind it is bad. It is just poorly implemented. But only criticizing is not fair. Let's see what you can do better. The problem of the gallery is the style sheet, which is simply written in the Post. [...]]]></description>
			<content:encoded><![CDATA[<p>There are things in WordPress, I do not like. This includes the gallery. Not that the idea behind it is bad. It is just poorly implemented. But only criticizing is not fair. Let's see what you can do better.</p>
<p><span id="more-1802"></span></p>
<p>The problem of the gallery is the style sheet, which is simply written in the Post. So that the page no longer validates. Additional problems arise when you want to change the look of the pictures in your theme for example. The style sheet in the post overwrites the values from the theme style sheet. How do the developers know if I like a 2px border #cfcfcf around my images? Something like this definitely does not belong in the code!</p>
<p>Cause of the problem is the ability to choose when you insert the gallery into the post, the number of columns (2-9). WordPress then calculates the width of the list elements by the number of selected columns and writes the values in the style sheet.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/gallery-settings.jpg" alt="WordPress Gallery settings" title="WordPress Gallery settings" width="434" height="308" class="aligncenter size-full wp-image-1803" /></p>
<h3>An own gallery function</h3>
<p>The function <strong>gallery_shortcode</strong>, which generates the gallery, can be found in wp-includes/media.php. For simplicity, we copy the complete function gallery_shortcode in to functions.php of the active theme. Then we rename the function, disable the function of WordPress and activate our own function:</p>
<pre lang="php">
//deactivate WordPress function
remove_shortcode(&#039;gallery&#039;, &#039;gallery_shortcode&#039;);

//activate own function
add_shortcode(&#039;gallery&#039;, &#039;wpe_gallery_shortcode&#039;);

//the own renamed function
function wpe_gallery_shortcode($attr) {
    ...
}
</pre>
<p>We are now going to call up a post with an inserted gallery. It should all work exactly as before, except that our own gallery function is now active. Now let us take any necessary changes to improve the output of the gallery.</p>
<p>First, we delete the following line. Which calculates the column. We do not need it anymore.</p>
<pre lang="php">
$itemwidth = $columns &gt; 0 ? floor(100/$columns) : 100;
</pre>
<p>Then we modify the variable $output. The style sheet will be completely erased. The inline style of the clearing <code>br</code> will be also removed. It's more elegant in its own theme style sheet. Finally, the last br-tag gets removed. The revised code $output should now look like this:</p>
<pre lang="php">
$output = apply_filters(&#039;gallery_style&#039;, &quot;
    &lt;div id=&#039;$selector&#039; class=&#039;gallery galleryid-{$id}&#039;&gt;&quot;);

$i = 0;
foreach ( $attachments as $id =&gt; $attachment ) {
    $link = isset($attr&#091;&#039;link&#039;&#093;) &amp;&amp; &#039;file&#039; == $attr&#091;&#039;link&#039;&#093; ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);

    $output .= &quot;&lt;{$itemtag} class=&#039;gallery-item&#039;&gt;&quot;;
    $output .= &quot;
        &lt;{$icontag} class=&#039;gallery-icon&#039;&gt;
            $link
        &lt;/{$icontag}&gt;&quot;;
    if ( $captiontag &amp;&amp; trim($attachment-&gt;post_excerpt) ) {
        $output .= &quot;
            &lt;{$captiontag} class=&#039;gallery-caption&#039;&gt;
            &quot; . wptexturize($attachment-&gt;post_excerpt) . &quot;
            &lt;/{$captiontag}&gt;&quot;;
    }
    $output .= &quot;&lt;/{$itemtag}&gt;&quot;;
    if ( $columns &gt; 0 &amp;&amp; ++$i % $columns == 0 )
        $output .= &#039;&lt;br /&gt;&#039;;
}

$output .= &quot;&lt;/div&gt;\n&quot;;

return $output;
</pre>
<p>After we have updated the post in our browser, we see all the pictures one below the other. But the document is valid. Now we need to create the column functionality again, that we have erased before. We simply add one additional class with the number of columns in $itemtag:</p>
<pre lang="php">
$output .= &quot;&lt;{$itemtag} class=&#039;gallery-item col-{$columns}&#039;&gt;&quot;;
</pre>
<p>In your source code, depending on the number of columns you see</p>
<pre lang="html4strict">
&lt;dl class=&quot;gallery-item col-5&quot;&gt;
</pre>
<p>Now, implement a few lines in the theme style sheet and the gallery is finished.</p>
<pre lang="css">
.gallery {
    margin: auto;
    /* gallery clearing*/
    overflow: hidden;
    width: 100%;
}
.gallery .gallery-item {
    float: left;
    margin-top: 10px;
    text-align: center;
}
.gallery img {
    border: 2px solid #cfcfcf;
}
.gallery .gallery-caption {
    margin-left: 0;
}
.gallery br { clear: both }

/* available Columns */
.col-2 { width: 50% }
.col-3 { width: 33.333% }
.col-4 { width: 25% }
.col-5 { width: 20% }
.col-6 { width: 16.666% }
.col-7 { width: 14.285% }
.col-8 { width: 12.5% }
.col-9 { width: 11.111% }
</pre>
<p><img src="http://wpengineer.com/wp-content/uploads/wordpress-gallery.jpg" alt="WordPress gallery" title="WordPress gallery" width="618" height="339" class="aligncenter size-full wp-image-1804" /></p>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1802/a-solution-for-the-wordpress-gallery/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Set options on activation Themes</title>
		<link>http://wpengineer.com/1705/set-options-on-activation-themes/</link>
		<comments>http://wpengineer.com/1705/set-options-on-activation-themes/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 10:09:56 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[The]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1705</guid>
		<description><![CDATA[The Photo Blog Theme Greyfoto has been updated and I wanted to make sure that the settings of WordPress are as I need them for the theme. Therefore must be written some data in the database when activate. Currently there is no hook for this, as is known for Plugins. The discussion on WP-Hacker-List was [...]]]></description>
			<content:encoded><![CDATA[<p>The Photo Blog Theme <a href="http://bueltge.de/photoblog-theme-greyfoto/837/"> Greyfoto </a> has been updated and I wanted to make sure that the settings of WordPress are as I need them for the theme. Therefore must be written some data in the database when activate. Currently there is no hook for this, as is known for Plugins. The discussion on <a href="http://www.nabble.com/Activation-hook-exist-for-themes--to25211004.html">WP-Hacker-List</a> was just right on time, and possibly Theme Developers get these hooks, similar to Plugins in WordPress 2.9.</p>
<p>If you want to use the activation of the theme in order to set various settings, then the following snippet can be very useful, which came up in the discussion on the WP-Hacker-List. This works like a charm and should be useful for theme developers who want to enable the options upon activation.<br />
<span id="more-1705"></span><br />
Here's a small example in which the default setting <code>posts_per_page</code> of WordPress in the table <code>options</code> is reset to the value 1.</p>
<pre lang="php">
// with activate istall option
if ( is_admin() &amp;&amp; isset($_GET&#091;&#039;activated&#039;&#093; ) &amp;&amp; $pagenow == &#039;themes.php&#039; ) {
	update_option( &#039;posts_per_page&#039;, 1 );
}
</pre>
<p>Since 2.9 you can use this function: <code>register_theme_directory</code><br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1705/set-options-on-activation-themes/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Themes and automatic_feed_links</title>
		<link>http://wpengineer.com/1655/themes-and-automatic_feed_links/</link>
		<comments>http://wpengineer.com/1655/themes-and-automatic_feed_links/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 11:56:13 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp2.8]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1655</guid>
		<description><![CDATA[Since WordPress 2.8, there is the function automatic_feed_links() in the function.php. Which writes the link elements for the RSS protocols in the header of the document. The advantage of this feature is, you do not need to worry about whether a change comes in the Feed-protocoll in a new version of WordPress, removed or a [...]]]></description>
			<content:encoded><![CDATA[<p>Since WordPress 2.8, there is the function <strong>automatic_feed_links()</strong> in the function.php. Which writes the link elements for the RSS protocols in the header of the document. The advantage of this feature is, you do not need to worry about whether a change comes in the Feed-protocoll in a new version of WordPress, removed or a new one is added.</p>
<p><! - more -><br />
If we develop a theme for the general public, you have 2 options. You use automatic_feed_links() and the theme does not work with WordPress prior to version 2.8, or you do not use this function and write the links as before, in your header.php.</p>
<p>I also have a 3rd alternative <img src='http://wpengineer.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<pre lang="php">
if (function_exists(&#039;automatic_feed_links&#039;)) {
    automatic_feed_links();
} else {
    add_action(&#039;wp_head&#039;, &#039;wpe_feed_links&#039;, 2);
}

function wpe_feed_links() {
    echo &#039;&lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;&#039;. get_bloginfo(&#039;name&#039;).&#039; RSS Feed&quot; href=&quot;&#039;. get_bloginfo(&#039;rss2_url&#039;).&#039;&quot; /&gt;&#039;;
    echo &#039;&lt;link rel=&quot;alternate&quot; type=&quot;application/atom+xml&quot; title=&quot;&#039;. get_bloginfo(&#039;name&#039;).&#039; Atom Feed&quot; href=&quot;&#039;. get_bloginfo(&#039;atom_url&#039;).&#039;&quot; /&gt;&#039;;
    echo &#039;&lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;&#039;. get_bloginfo(&#039;name&#039;).&#039; &#039;. __(&#039;The latest comments to all posts in RSS&#039;).&#039;&quot; href=&quot;&#039;. get_bloginfo(&#039;comments_rss2_url&#039;).&#039;&quot; /&gt;&#039;;
}
</pre>
<p>First we look if the function automatic_feed_links() exists. If not (prior to WP 2.8), we use the hook wp_head and write the links in the header of the page. Thus we don't need to adjust the header.php anymore.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1655/themes-and-automatic_feed_links/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Change WordPress Mail Sender</title>
		<link>http://wpengineer.com/1604/change-wordpress-mail-sender/</link>
		<comments>http://wpengineer.com/1604/change-wordpress-mail-sender/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 10:55:04 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1604</guid>
		<description><![CDATA[WordPress makes it easy and fast to add new users in the backend. Since version 2.8 of WordPress, it can send the access information via email. A nice feature, with no additional settings to change the sender of this email. For example the email should be send from the administrator instead from WordPress. Nevertheless, there [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress makes it easy and fast to add new users in the backend. Since version 2.8 of WordPress, it can send the access information via email. A nice feature, with no additional settings to change the sender of this email. For example the email should be send from the administrator instead from WordPress.</p>
<p>Nevertheless, there is a possibility and with the help of two hooks, the sender can be changed. I created a small Plugin, where you can easy and simple adjust the sender name and sender email.<br />
<span id="more-1604"></span>-<br />
The Plugin is available in the following source code and has no options for the backend and doesn't leave any data in the database. Anyone who wants can simply extend the Plugin.</p>
<pre lang="php">
&lt;?php
/**
 * @package WP Mail From
 * @author Frank B&uuml;ltge
 * @version 0.1
 */

/*
Plugin Name: WP Mail From
Plugin URI: http://bueltge.de/
Description: Change the default address that WordPress sends it&rsquo;s email from.
Version: 0.1
Author: Frank B&uuml;ltge
Author URI: http://bueltge.de/
Last Change: 11.08.2009 08:41:06
*/

if ( !function_exists(&#039;add_action&#039;) ) {
	header(&#039;Status: 403 Forbidden&#039;);
	header(&#039;HTTP/1.1 403 Forbidden&#039;);
	exit();
}

if ( !class_exists(&#039;wp_mail_from&#039;) ) {
	class wp_mail_from {

		function wp_mail_from() {
			add_filter( &#039;wp_mail_from&#039;, array(&amp;$this, &#039;fb_mail_from&#039;) );
			add_filter( &#039;wp_mail_from_name&#039;, array(&amp;$this, &#039;fb_mail_from_name&#039;) );
		}

		// new name
		function fb_mail_from_name() {
			$name = &#039;My Blog is my Blog&#039;;
			// alternative the name of the blog
			// $name = get_option(&#039;blogname&#039;);
			$name = esc_attr($name);
			return $name;
		}

		// new email-adress
		function fb_mail_from() {
			$email = &#039;info@example.com&#039;;
			$email = is_email($email);
			return $email;
		}

	}

	$wp_mail_from = new wp_mail_from();
}
?&gt;</pre>
<p>The values for name and email have to be maintain in each of the associated function. After that, the two values are getting examined, but is not necessarily needed.</p>
<p>As a note: the function <code>esc_attr()</code> is only since version 2.8 available and replaces the function <code>attribute_escape()</code>. Should the solution be used in an earlier version, then you have to change the function.</p>
<p>For suggestions and improvements, I am grateful, as always. You can use this Plugin to improve WordPress a bit and the user is not surprised about the sender "WordPress".<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1604/change-wordpress-mail-sender/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Correct Pagination with get_posts</title>
		<link>http://wpengineer.com/1263/correct-pagination-with-get_posts/</link>
		<comments>http://wpengineer.com/1263/correct-pagination-with-get_posts/#comments</comments>
		<pubDate>Thu, 28 May 2009 22:36:29 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[get_posts]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1263</guid>
		<description><![CDATA[If you like to show your posts a little bit different on your homepage or category page. For example having a different amount of posts showing on these pages, as it is set in your admin, you will get a problem with the pagination function. Because WordPress and several paging Plugins use $wp_query->max_num_pages. max_num_pages is [...]]]></description>
			<content:encoded><![CDATA[<p>If you like to show your posts a little bit different on your homepage or category page. For example having a different amount of posts showing on these pages, as it is set in your admin, you will get a problem with the pagination function. Because WordPress and several paging Plugins use <strong>$wp_query->max_num_pages</strong>.<br />
<span id="more-1263"></span><br />
<code>max_num_pages</code> is the result of available posts divided by the set number of posts per page. For example we set 10 posts per page, but we have on our starting page 14 posts, it will mess up the pagination.</p>
<p>My solution works with the WordPress pagination and looks like this:</p>
<pre lang="php">
//detect the set number of posts per page
$ppp = get_option(&#039;posts_per_page&#039;);

// first page 14 posts
if (!is_paged()) {
    $posts = get_posts(&#039;numberposts=14&#039;);
// second page with offset
} elseif($paged == 2) {
    $posts = get_posts(&#039;offset=14&#039;);
// all other pages with settings from backend
} else {
    $offset = $ppp*($paged-2)+14;
    $posts = get_posts(&#039;offset=&#039;.$offset);
}

if($posts) :
    foreach ($posts as $post) :
        //your code
    endforeach;
endif;
</pre>
<p>This might be not the most intelligent solution, but it works. If anybody has a better idea, please let us know in the comments.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1263/correct-pagination-with-get_posts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Different Favicons For Backend And Frontend</title>
		<link>http://wpengineer.com/1068/different-favicons-backend-frontend/</link>
		<comments>http://wpengineer.com/1068/different-favicons-backend-frontend/#comments</comments>
		<pubDate>Mon, 18 May 2009 16:03:31 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Favicon]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1068</guid>
		<description><![CDATA[Do you have the same problem? We all have a lot tabs open, especially of our own blogs and all tabs look the same, since there is the same favicon for backend and frontend in your tabs. It can be annoying to click around to find the admin tab between all the opened tabs of [...]]]></description>
			<content:encoded><![CDATA[<p>Do you have the same problem? We all have a lot tabs open, especially of our own blogs and all tabs look the same, since there is the same favicon for backend and frontend in your tabs. It can be annoying to click around to find the admin tab between all the opened tabs of some posts of your blog. As you can see on this screenshot:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/favicon-wpengineer.jpg" alt="favicon-wpengineer" title="favicon-wpengineer" width="450" height="209" class="aligncenter size-full wp-image-1251" /></p>
<p>A little hack in your <code>functions.php</code> of your theme can help you with this problem:</p>
<pre lang="php">
/* Different Favicon for Backend */
function favicon4admin() {
 echo &#039;&lt;link rel=&quot;Shortcut Icon&quot; type=&quot;image/x-icon&quot; href=&quot;&#039; . get_bloginfo(&#039;wpurl&#039;) . &#039;/wp-content/favicon.ico&quot; /&gt;&#039;;
}
add_action( &#039;admin_head&#039;, &#039;favicon4admin&#039; );
</pre>
<p>In this case we put the admin favicon in our <code>wp-content</code> folder. Done!</p>
<p><img src="http://wpengineer.com/wp-content/uploads/favicon-wpengineer2.jpg" alt="favicon-wpengineer2" title="favicon-wpengineer2" width="450" height="209" class="aligncenter size-full wp-image-1254" /></p>
<p>It can be a little helpful hack for your daily work. Of course, the text in the tabs are different most of the time, but not always, and a different looking favicon is more visible. </p>
<p>An easy tool to create a favicon is <a href="http://tools.dynamicdrive.com/favicon/">available at dynamicdrive</a><br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1068/different-favicons-backend-frontend/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Secure Your Mail With WordPress Antispambot Function</title>
		<link>http://wpengineer.com/849/wordpress-antispambot/</link>
		<comments>http://wpengineer.com/849/wordpress-antispambot/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 22:01:23 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[antispambot]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=849</guid>
		<description><![CDATA[A little-known feature in WordPress is antispambot() from the wp-includes/formatting.php. It is a kind obfuscator of the email address. It doesn't create a clickable mailto link. Our e-mail with antispambot in the source code looks like this: You cannot use this function in a post or page unless you installed the EXEC-PHP Pluging. Kai had [...]]]></description>
			<content:encoded><![CDATA[<p>A little-known feature in WordPress is <strong>antispambot() </strong> from the wp-includes/formatting.php. It is a kind obfuscator of the email address. It doesn't create a clickable mailto link. Our e-mail with antispambot in the source code looks like this:<br />
<span id="more-849"></span><br />
<img class="aligncenter size-full wp-image-851" title="Screenshot WordPress antispambot email" src="http://wpengineer.com/wp-content/uploads/antispambot-wordpress.jpg" alt="Screenshot WordPress antispambot email" width="450" height="94" /></p>
<p>You cannot use this function in a post or page unless you installed the EXEC-PHP Pluging. <a title="Kais german blog" href="http://sokai.name">Kai</a> had the cool idea to use shortcodes for this. This function belongs in the function.php of your theme folder:</p>
<pre lang="php">
&lt;?php
function wpe_secure_mail($atts) {
	extract(shortcode_atts(array(
		&quot;mailto&quot; =&gt; &#039;&#039;,
		&quot;txt&quot; =&gt; &#039;&#039;
	), $atts));
	$mailto = antispambot($mailto);
	$txt = antispambot($txt);
	return &#039;&lt;a href=&quot;mailto:&#039; . $mailto . &#039;&quot;&gt;&#039; . $txt . &#039;&lt;/a&gt;&#039;;
}

if ( function_exists(&#039;add_shortcode&#039;) )
	add_shortcode(&#039;sm&#039;, &#039;wpe_secure_mail&#039;);
?&gt;
</pre>
<p>This shortcode will be used to write in your post/page:</p>
<pre lang="php">
&#091;sm mailto=&quot;foo@bar.com&quot; txt=&quot;here is my mail&quot;&#093;
//or
&#091;sm mailto=&quot;foo@bar.com&quot; txt=&quot;foo@bar.com&quot;&#093;
</pre>
<p>Here an example, look at the source code of this page:<br />
[sm mailto="info@wpengineer.com" txt="info@wpengineer.com"]<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/849/wordpress-antispambot/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

