Is it acceptable to treat a filter like an action?

All actions are actually filters internally. So yes, you can do things in a filter hook. However, be mindful of which filters and what you’re doing. Some filters are ran everywhere, and doing expensive operations on them may lead to massive slowdowns. Also beware of recursion. If your expensive operation triggers the very filter you’ve … Read more

PHP Script for last login time

I found it. After a lot of research I found the way to hook into logout and get user data, and as i was looking for that i found the exact answer i was looking for. function users_last_login() { $cur_login = current_time(‘mysql’); $userinfo = wp_get_current_user(); update_user_meta( $userinfo->ID, ‘last_login’, $cur_login ); } add_action(‘clear_auth_cookie’, ‘users_last_login’, 10); Thanks … Read more

Remove wp_admin_bar fail on wordpress 4.0

You must use show_admin_bar(false); for disabling admin bar to disable admin bar for all except admin add this to functions.php add_action(‘after_setup_theme’, ‘remove_admin_bar’); function remove_admin_bar() { if (!current_user_can(‘administrator’) && !is_admin()) { show_admin_bar(false); } } you can refer about that here

Change behavior of the tag

It sounds like this is a problem with the way your theme is setup, since what you describe isn’t the usual behaviour of the more tag. The first part of your post suggests there’s some built-in Javascript in your theme causing the read more to expand the post text rather than take you to the … Read more

Sort posts by custom fields value using dropdown menu

Instead of query_posts try using WP_Query class. http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters This is example from codex: $args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_key’ => ‘age’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array( 3, 4 ), ‘compare’ => ‘IN’, ), ), ); $query = new WP_Query( $args );

Set the background to a default image if there isn’t a specified “featured image”

I found the solution from a WordPress forum and this is what they used. Works perfect <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ” ); $image = $image[0]; ?> <?php else : $image = get_bloginfo(‘stylesheet_directory’) . ‘/lib/images/home1-1024×681.jpg’; ?> <?php endif; ?> <section id=”halfpro” style=”background-image: url(‘<?php echo $image; ?>’)” … Read more

Extending the WP_Widget_Text class

Think about it, why would WordPress do anything just because you have defined additional class? It’s not magic (neither magical magic or code driven magic). The text widget doesn’t appear simply because class exists. When WordPress loads it runs wp_widgets_init(), which executes register_widget(‘WP_Widget_Text’). So technically you cannot tell it to use different class. What you … Read more

Increase returned number/pages on pagination

Refer to the Codex page for paginate_links for all accepted arguments. The two you want to modify are mid_size and possibly end_size. $output .= paginate_links( array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ => ‘?paged=%#%’, ‘current’ => max( 1, get_query_var(‘paged’) ), ‘total’ => $wp_query->max_num_pages, ‘mid_size’ => 8 // number of … Read more

Converting HTML Template to WordPress Theme

As said, you should enqueue your style sheets like this in your functions.php in your theme: function adds_to_the_head() { // Our own unique function called adds_to_the_head wp_register_style( ‘custom-style-css’, get_stylesheet_directory_uri() . ‘/css/styles.css’,”,”, ‘screen’ ); // Register style.css wp_enqueue_style( ‘custom-style-css’ ); // Enqueue our stylesheet } add_action( ‘wp_enqueue_scripts’, ‘adds_to_the_head’ );