Užitečné pluginy, návody a šablony pro WordPress CMS

Užitečné hooks & filters

Modify post title when some string exists in the post content
Add lock icon if there is a member shortcode present in the post content.
Without $post->ID == $id not only post title is changed but also menu items and next/previous links.

function modify_title($title, $id) {
    global $post;
    $content = $post->post_content;
    if(strpos($content, '[member]') AND $post->ID == $id) {
        $theme_dir = get_bloginfo('stylesheet_directory');
        $lock = ' <img src="'.$theme_dir.'/images/lock.gif" border="0"/>';
        $new_title = $title.$lock;
        return $new_title;
    } else {
        return $title;
add_filter('the_title', 'modify_title', 10, 2);

Add extra contact methods to user profiles

By default, WordPress allow users to enter an AIM name on their profile, but no Facebook and no Twitter names! In order to add more contact methods to user profile, simply paste this hook in your functions.php file. In this example it will add Facebook and Twitter, but it can be used for any website or service you need.

function my_user_contactmethods($user_contactmethods){
  $user_contactmethods['twitter'] = 'Twitter Username';
  $user_contactmethods['facebook'] = 'Facebook Username';

  return $user_contactmethods;

add_filter('user_contactmethods', 'my_user_contactmethods');

Automatically enable threaded comments

By default, WordPress do not enable threaded comments. If you want/need to change this, here is a handy code snippet to paste in your functions.php file:

function enable_threaded_comments(){
 if (!is_admin()) {
  if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))

add_action('get_header', 'enable_threaded_comments');

Automatically replace words in your posts

function replace_text_wps($text){
    $replace = array(
        'wordpress' => '<a href="#">wordpress</a>',
        'excerpt' => '<a href="#">excerpt</a>',
        'function' => '<a href="#">function</a>'
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;

add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');

Quick maintenance mode

function cwc_maintenance_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        wp_die('Maintenance, please come back soon.');
add_action('get_header', 'cwc_maintenance_mode');

Zdroj »

Přidání boxu pro excerpt (stručný výpis) i do stránek

function enable_page_excerpt() {
add_post_type_support( 'page', 'excerpt' );
add_action('init', 'enable_page_excerpt');

Deaktivace HTML v komentářích

add_filter('pre_comment_content', 'wp_specialchars');

10 Useful WordPress Hook Hacks »

OVX.cz 2003 | Přihlásit se
Bez cookies už dnes těžko provozovat plnohodnotný web. Setrváním zde tudíž vyjadřujete souhlas s jejich používáním. Více informací. | Zavřít.