[sticky] [closed] WordPress Hacks (241 posts)

  1. rss milo

    moderator


    rss Posted 7 months ago
    #

    Show parent page title regardless of what subpage you are on

    <?php
    if($post->post_parent) {
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    } else {
    wp_title('');
    }
    ?>

  2. rss milo

    moderator


    rss Posted 7 months ago
    #

    hide login error messages

    add_filter('login_errors',create_function('$a', "return null;"));

  3. rss milo

    moderator


    rss Posted 3 months ago
    #

    Create “Search By Category”

    code in sidebar

    <form id="searchform" method="get" action="<?php bloginfo('url'); ?>">
    <input type="text" name="s" id="s" size="15" />
    <?php wp_dropdown_categories('show_option_none=Select category'); ?>
    <input type="submit" value="Search" />
    </form>

    code in functions

    add_action('pre_get_posts', 'search_by_cat');
    function search_by_cat()
    {
    global $wp_query;
    if (is_search()) {
    $cat = intval($_GET['cat']);
    $cat = ($cat > 0) ? $cat : '';
    $wp_query->query_vars['cat'] = $cat;
    }
    }

  4. rss milo

    moderator


    rss Posted 3 months ago
    #

    Custom Default Avatar For BuddyPress

    code in functions

    function myavatar_add_default_avatar( $url )
    {
    return get_stylesheet_directory_uri() .'/images/myimage.jpg';
    }
    add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );

    Change the Default Avatar

    function my_default_get_group_avatar($avatar) {
    global $bp, $groups_template;
    if( strpos($avatar,'group-avatars') ) {
    return $avatar;
    }
    else {
    $custom_avatar = get_stylesheet_directory_uri() .'/images/myimage.jpg';
    if($bp->current_action == "")
    return 'group->name ) . '" />';
    else
    return 'group->name ) . '" />';
    }
    }
    add_filter( 'bp_get_group_avatar', 'my_default_get_group_avatar');

  5. rss milo

    moderator


    rss Posted 3 months ago
    #

    Highlight Current Category Menu Item

    code in functions

    function sgr_show_current_cat_on_single($output) {
    global $post;
    if( is_single() ) {
    $categories = wp_get_post_categories($post->ID);
    foreach( $categories as $catid ) {
    $cat = get_category($catid);
    // Find cat-item-ID in the string
    if(preg_match('#cat-item-' . $cat->cat_ID . '#', $output)) {
    $output = str_replace('cat-item-'.$cat->cat_ID, 'cat-item-'.$cat->cat_ID . ' current-cat', $output);
    }
    }
    }
    return $output;
    }
    add_filter('wp_list_categories', 'sgr_show_current_cat_on_single');

  6. rss milo

    moderator


    rss Posted 3 months ago
    #

    Display Custom Message

    <?php if(isset($_COOKIE['comment_author_'.COOKIEHASH])) {
    $lastCommenter = $_COOKIE['comment_author_'.COOKIEHASH];
    echo "Welcome Back ". $lastCommenter ."!";
    } else {
    echo "Welcome, Guest!";
    } ?>

  7. rss milo

    moderator


    rss Posted 3 months ago
    #

    Display Recently Updated Posts

    <?php

    $today = current_time('mysql', 1);
    $number = 5; // number of posts

    if($recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $number")):

    ?>

    <h2><?php _e("Recently Updated"); ?></h2>
    < ul>
    <?php
    foreach($recentposts as $post) {
    if($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
    echo '< li>< a href="'.get_permalink($post->ID).'">'.the_title().'</ a></ li>';
    } ?>
    </ ul>
    <?php endif; ?>

  8. rss milo

    moderator


    rss Posted 3 months ago
    #

    Display Content to Search Engine Visitors

    functions:

    <?php function scratch99_fromasearchengine() {
    $ref = $_SERVER['HTTP_REFERER'];
    $SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
    foreach($SE as $source) {
    if(strpos($ref, $source) !== false) return true;
    }
    return false;
    } ?>

    template

    <?php if(function_exists('scratch99_fromasearchengine')) {
    if (scratch99_fromasearchengine()) {
    // INSERT YOUR CODE HERE
    }
    } ?>

Topic Closed

This topic has been closed to new replies.