Tag Info

Hot answers tagged

72

Enable Hidden Admin Feature displaying ALL Site Settings Tested on: Wordpress 3.1 RC3 This little piece of code does something pretty cool. It will add an additional option to your settings menu with a link to "all settings" which will show you a complete list of all the settings you have within your database related to your wordpress site. The code below ...


60

The plugins are loaded right before theme (yes, I've been looking for excuse to use this): However it is wrong to think about either as point of code execution. For most cases everything should be hooked and executed no earlier than init hook. According to Codex widget registration with register_widget() should be hooked to widget_init. Because of that ...


58

Modify the Login Logo & Image URL Link Tested on: WordPress 3.0.1 This code will allow you to easily modify the WordPress Login page Logo as well as the href link and title text of this logo. add_filter( 'login_headerurl', 'namespace_login_headerurl' ); /** * Replaces the login header logo URL * * @param $url */ function namespace_login_headerurl( ...


53

Remove Update Notification for all users except ADMIN User Tested on: Wordpress 3.0.1 This code will ensures that no users other than "admin" are notified by wordpress when updates are available.. // REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN global $user_login; get_currentuserinfo(); if ($user_login !== "admin") { // ...


50

Include custom post types in the search results. // MAKE CUSTOM POST TYPES SEARCHABLE function searchAll( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); } return $query; } add_filter( 'the_search_query', 'searchAll' ); Add your custom post types to your sites main RSS feed by ...


49

Loading jQuery from the Google CDN Tested on: Wordpress 3.0.1 // even more smart jquery inclusion :) add_action( 'init', 'jquery_register' ); // register from google and for footer function jquery_register() { if ( !is_admin() ) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', ( ...


40

Wordpress Profiling tools I like to add profiling tools in a separate file, which I then include from functions.php when needed: <?php if ( !defined('SAVEQUERIES') && isset($_GET['debug']) && $_GET['debug'] == 'sql' ) define('SAVEQUERIES', true); if ( !function_exists('dump') ) : /** * dump() * * @param mixed $in * @return mixed ...


39

Set a maximum number of post revisions to avoid DB bloat. Tested on: Wordpress 3.0.1 Default is infinite, this will set it to only remember last 5 edits: /** * Set the post revisions unless the constant was set in wp-config.php */ if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 5); FWIW there are a ton of great ideas for CONSTANTS that ...


38

Remove Default Wordpress Meta Boxes Tested on: Wordpress 3.0.1 This code will allow you to remove specific Meta Boxes which wordpress adds by default to the default Add/Edit Post and Add/Edit Page screens. // REMOVE META BOXES FROM DEFAULT POSTS SCREEN function remove_default_post_screen_metaboxes() { remove_meta_box( 'postcustom','post','normal' ); ...


34

Add Custom User Profile Fields Place the code below into your functions.php file to add custom user profile fields. Edit or add lines as you see fit. Remember not to remove the line: return $contactmethods; otherwise this won't work. // CUSTOM USER PROFILE FIELDS function my_custom_userfields( $contactmethods ) { // ADD CONTACT CUSTOM FIELDS ...


34

Here's the process to change the labels (I changed posts to "contacts" in my example) function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'Contacts'; $submenu['edit.php'][5][0] = 'Contacts'; $submenu['edit.php'][10][0] = 'Add Contacts'; $submenu['edit.php'][15][0] = 'Status'; // Change name for categories ...


32

Remove "Wordpress" to "WordPress" filter Tested on: Wordpress 3.0.1 There was a filter added with WordPress version 3.0 that automatically converts all instances of "Wordpress" (no capital P) to "WordPress" (with a capital P) in post content, post titles, and comment text. Some people see this as intrusive, I just have a need to mis-case WordPress from ...


31

Customize the order of the admin menu tested on: Wordpress 3.0.1 This code will allow you to reorganize the order of elements in the admin menu. All that you need to do is click on an existing link in the admin menu and copy everything before the /wp-admin/ URL. The order below represents the order the new admin menu will have. // CUSTOMIZE ADMIN MENU ...


28

Customize the Dashboard add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets'); function my_custom_dashboard_widgets() { global $wp_meta_boxes; Remove these dashboard widgets... unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); ...


28

Add Thumbnails in Manage Posts/Pages List You can add this to your functions to display to the Manage/Edit Post and Pages List a new column with the thumbnail preview. /****** Add Thumbnails in Manage Posts/Pages List ******/ if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) { // for post and page ...


27

Function to change the length of Exerpt Tested on: Wordpress 3.0.1 By default all excerpts are capped at 55 words. Utilizing the code below you can override this default settings: function new_excerpt_length($length) { return 100; } add_filter('excerpt_length', 'new_excerpt_length'); This example changes the excerpt length to 100 words, but you ...


26

Auto Extract the First Image from the Post Content Tested on: Wordpress 3.0.1 This code will automatically extract the first image associated with a post and allow you to display/use it by calling the getImage function. // AUTOMATICALLY EXTRACT THE FIRST IMAGE FROM THE POST function getImage($num) { global $more; $more = 1; $link = ...


26

Remove pings to your own blog Tested on: Wordpress 3.0.1 //remove pings to self function no_self_ping( &$links ) { $home = get_option( 'home' ); foreach ( $links as $l => $link ) if ( 0 === strpos( $link, $home ) ) unset($links[$l]); } add_action( 'pre_ping', 'no_self_ping' );


24

Sharpen Resized Images (only jpg) This function sharpening resized jpg images. An example of difference: function ajx_sharpen_resized_files( $resized_file ) { $image = wp_load_image( $resized_file ); if ( !is_resource( $image ) ) return new WP_Error( 'error_loading_image', $image, $file ); $size = @getimagesize( $resized_file ); ...


23

Display DB Queries, Time Spent and Memory Consumption Tested on: Wordpress 3.0.1 function performance( $visible = false ) { $stat = sprintf( '%d queries in %.3f seconds, using %.2fMB memory', get_num_queries(), timer_stop( 0, 3 ), memory_get_peak_usage() / 1024 / 1024 ); echo $visible ? $stat : "<!-- {$stat} ...


23

Enable GZIP output compression Normally the server should be set up to do this automatically, but a lot of shared hosts don t do this (probably to increase client bandwidth usage) if(extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler")) add_action('wp', create_function('', ...


23

You should run the code after theme setup. function osu_twentyten_continue_reading_link() { return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>'; } function osu_twentyten_auto_excerpt_more( $more ) { return ' &hellip;' . ...


21

There is a global variable in wp-admin called $pagenow which holds name of the current page, ie edit.php, post.php, etc. You can also check the $_GET request to narrow your location down further, for example: global $pagenow; if (( $pagenow == 'post.php' ) && ($_GET['post_type'] == 'page')) { // editing a page } if ($pagenow == ...


21

Remove Plugin Update Notice ONLY for INACTIVE plugins function update_active_plugins($value = '') { /* The $value array passed in contains the list of plugins with time marks when the last time the groups was checked for version match The $value->reponse node contains an array of the items that are out of date. This response node is ...


21

Unregister WP Default Widgets Tested on: Wordpress 3.0.1 // unregister all default WP Widgets function unregister_default_wp_widgets() { unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); ...


20

Output which theme template file a post/page is using in the header add_action('wp_head', 'show_template'); function show_template() { global $template; print_r($template); } Shorten the default DIV output if your theme is using post_class. if your theme is using something like <div id="post-<?php the_ID(); ?>" <?php post_class(); ...


20

Coming in late to this party, but here's the "WordPress" way: use plugin_dir_path( __FILE__ ), e.g.: <?php include( plugin_dir_path( __FILE__ ) . 'ipn/paypal-ipn.php'); ?> Note that the function does return the trailing slash for the filepath.


17

Automatically Add Dynamic Titles to Public Pages Tested on: Wordpress 3.0.1 Utilizing the code below will automatically create dynamic page titles based upon the pages/posts being viewed publicly. /* Dynamic Titles **/ // This sets your <title> depending on what page you're on, for better formatting and for SEO // You need to set the variable $longd ...


16

New Roles and Capabilities - Only run once! I keep these handy, this is the right way to do them without a plugin. They set a single field (prefix_user_roles) in the options database, and you don't need a plugin to set them. Refer to the Codex page for a list of what capabilities are available and descriptions for what they do. You only need to uncomment ...



Only top voted, non community-wiki answers of a minimum length are eligible