List of Body Classes Generated by body_class()

Several classes have been added since WordPress 2.8 (when the WPEngineer post was written). I would refer directly to the body_class() Codex entry, which currently lists the following: rtl home blog archive date search paged attachment error404 single postid-(id) page-id-(page_id) attachmentid-(id) attachment-(mime-type) author author-(user_nicename) category category-(slug) tag tag-(slug) page-parent page-child parent-pageid-(id) page-template page-template-(template file name) … Read more

Display gallery on top before content

function gallery_first( $content) { $expr=”/\[gallery(.*?)\]/i”; return preg_replace_callback( $expr, create_function(‘$matches’, ‘return do_shortcode($matches[0]);’), $content); } add_filter( ‘the_content’, ‘gallery_first’, 6); // prio 6 executes this function previous to all other filter functions

How to select a page within admin?

add_action( ‘add_meta_boxes_page’, ‘wpse_57924_remove_editor’ ); function wpse_57924_remove_editor( $post ) { if ( $post->ID == get_option( ‘page_on_front’ ) /* or hardcode ID if not front page */ ) remove_post_type_support( ‘page’, ‘editor’ ); }

Get the 5 lastest Featured Posts from a category

<?php /* Set the name of the category and the number os posts to be displayed */?> <?php $first_query = new WP_Query(‘category_name=name&posts_per_page=7’); ?> <?php /* Show the posts */ ?> <?php while ($first_query->have_posts()) : $first_query->the_post(); ?> <?php /* Make the hiperlink to the post */ ?> <a href=”https://wordpress.stackexchange.com/questions/59934/<?php the_permalink(); ?>”> <?php /* Get the featured … Read more

edit role display name and label name without plugins

Those names are stored in the option wp_user_roles in the database table wp_options. So, the following will change the name of the subscriber role: $val = get_option( ‘wp_user_roles’ ); $val[‘subscriber’][‘name’] = ‘PeDeBoi’; update_option( ‘wp_user_roles’, $val ); Apparently, this is harmless, but caveat emptor… In your code, $wp_roles->roles[$role][‘name’] = $new_role_name; doesn’t work because it should be: … Read more

Change Rating range in Link Manager

See the function link_advanced_meta_box() in wp-admin/includes/meta-boxes.php: <td><select name=”link_rating” id=”link_rating” size=”1″> <?php for ( $r = 0; $r <= 10; $r++ ) { echo ‘<option value=”‘ . $r . ‘”‘; if ( isset($link->link_rating) && $link->link_rating == $r ) echo ‘ selected=”selected”‘; echo(‘>’ . $r . ‘</option>’); } ?></select>&nbsp;<?php _e(‘(Leave at 0 for no rating.)’) ?> The … Read more

Defining a global array in functions.php?

In order to access a variable defined in the global scope you must reference it with the global keyword wherever you want to call it again. In your case, the function create_year_terms() must call the global $year_arr within its scope. Also, you can always get your variable in the global scope by using the $GLOBALS … Read more

2 Loops, Only Displaying 1 Loop in Both Loops

You can’t add the pre_get_posts action right before the loop. You HAVE to do it in functions.php. It has to be set before the site actually queries the db to set up the loop which happens before your template file is loaded. What you are doing is looping through the exact same query twice, because … Read more