Sharing functions between plugins

If you want the theme to be independent from the CPT’s, place the CPT’s as plugin(s). If the CPTs go with the theme, functions.php sounds like the perfect spot for them. If you add them as plugins, you should group them in one or more plugins depending on functionality, not on post type.

update_post_meta is Updating with two page id

It’s probably Firefox prefetching pages, which it can do based on the rel attribute of links (see https://stackoverflow.com/a/18156967/664741). You could alter these links to remove eg rel=”next”, or you could detect Firefox prefetching by checking the headers sent: if ( ! isset( $_SERVER[‘HTTP_X_MOZ’] ) || $_SERVER[‘HTTP_X_MOZ’] != ‘prefetch’ ) { add_action( ‘wp’, ‘function_name’ ); }

Sort and display pages with specific custom field (not tag)

Thanks @PieterGoosen and @realloc. I came up with this solution: Added meta_key=important&meta_value=1 in wp_list_pages(). And gonna use custom field for pages important: 1. This is for list of IMPORTANT child pages. function important_list_child_pages() { global $post; if ( is_page() && $post->post_parent ) $childpages = wp_list_pages( ‘meta_key=important&meta_value=1&sort_column=menu_order&title_li=&child_of=” . $post->post_parent . “&echo=0’ ); else $childpages = wp_list_pages( … Read more

Is it legal to redefine wp_password_change_notification in a mu plugin?

Here are the contents of a working example, placed in a php file in wp-includes/mu-plugins/. The email is sent when a user completes the password reset action after clicking the reset link in the email they receive. <?php if( ! function_exists( ‘wp_password_change_notification’ ) ){ function wp_password_change_notification( &$user ){ wp_mail( get_option(‘admin_email’), ‘Test’, ‘test’ ); } }

How to add author’s posts link (HTML + PHP) inside a function to output it

Try adding this line right after the one you mention: $outputSlide .= ‘<a href=”‘ . get_author_posts_url( get_the_author_meta( ‘ID’ ) ) . ‘”>’ . get_the_author_meta( ‘display_name’ ) . ‘</a>’; Note change of the_author_meta() to get_the_author_meta(). the_author_meta() will echo the result, whereas get_the_author_meta() just gets the result which is added to the $outputSlide variable and returned as … Read more

How to hightlight all ancestor menu items of a child page NOT displayed in menu

You are checking against just one parent item. Instead, you might check against all of the parents <?php //in functions.php add_filter(‘nav_menu_css_class’, ‘highlight_portfolio’, 12, 2); function highlight_portfolio($classes, $item) { $parents = get_post_ancestors(); if ( 0 < count($parents) ) { if ( in_array( $item->object_id, $parents ) { array_push( $classes, ‘current-menu-ancestor’ ); } } return $classes; } Notice … Read more

Modify shortcode to work with custom post types

This part of the code is what defines the arguments that can be passed with the shortcode: extract(shortcode_atts(array( “posts” => ‘8’, “columns” => ‘4’, “category” => ”, “style” => ‘text-normal’, “image_height” => ‘auto’, “show_date” => ‘true’, “excerpt” => ‘true’, ), $atts)); This allows you to later on use this values as $posts, $columns and so … Read more

Trying to get property of non-object in: $wp_query

get_object_vars() returns an associative array of object properties – so queried_object is never in $wpQueryObj, it’s a key: $wpQueryObj[‘queried_object’]. Besides, you shouldn’t be doing any of that anyway – use get_queried_object(): if ( $wp_query instanceof WP_Query ) { if ( $object = $wp_query->get_queried_object() ) { $query_name = isset( $object->name ) ? $object->name : ”; } … Read more

Custom Taxonomy Select Menu: Setting default option value?

Simply add an extra line before your for loop. For example: function get_color_dropdown($taxonomies, $args){ $myterms = get_terms($taxonomies, $args); $output =”<select onChange=”window.location.href=this.value”>”; $output .= “<option value=”default”>Shop by Color –></option>”; foreach($myterms as $term){ $root_url = get_bloginfo(‘url’); $term_taxonomy=$term->taxonomy; $term_slug=$term->slug; $term_name =$term->name; $link = $root_url.”https://wordpress.stackexchange.com/”.$term_taxonomy.”https://wordpress.stackexchange.com/”.$term_slug; $output .=”<option value=””.$link.””>”.$term_name.”</option>”; } $output .=”</select>”; return $output; } $taxonomies = array(‘pa_color’); $args = … Read more