Created
February 25, 2013 09:43
-
-
Save vicchi/5028778 to your computer and use it in GitHub Desktop.
Example of the WP Biographia WordPress plugin's wp_biographia_link_item filter; appends the current post's title to the Biography Box's mailto link. Copy and paste this code into the bottom of your theme's functions.php.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter ('wp_biographia_link_item', 'filter_link_item', 10, 2); | |
function filter_link_item ($content, $params) { | |
// $params = array ( | |
// 'type' => 'link type (icon|text)', | |
// 'format' => 'link format string', | |
// 'meta' => 'additional anchor attributes', | |
// 'title' => 'link title', | |
// 'url' => 'link URL', | |
// 'body' => 'link body text', | |
// 'link-class' => 'link CSS class name', | |
// 'item-class' => 'link item CSS class name (icons only)' | |
// ); | |
$url = $params['url']; | |
if (is_single ()) { | |
$pos = strpos ($url, 'mailto:'); | |
if ($pos === 0) { | |
global $post; | |
$url .= '?subject=' . $post->post_title; | |
$content = sprintf ($params['format'], $url, $params['meta'], $params['title'], $params['link-class'], $params['body'], $params['item-class']); | |
} | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment