Check if post belongs to any category

get_the_terms return and error on failure. So before your foreach loop check for the error and only run it if there is none, using is_wp_error. <?php $myterms = get_the_terms( $post->ID, ‘portfolio_category’ ); if( !is_wp_error( $myterms ) ) foreach( $myterms as $myterm ) echo $myterm->slug . ‘<br />’; ?>

HowTo to add my rewrite rules at the beginning, redirect to the right page and flush the rules on plugin activation?

Parameter in add_permastruct() The third parameter of add_permastruct() is for the is_front parameter. This is a basename, which you can add to the default permalink structure of all your posts in the WordPress admin. For example, if you have set the permalink structure to /blog/%postname% the word blog will be prepended to your rule. In … Read more

making a plugin that moves other plugins wp_head actions to wp_footer

Remove the action, then add it back on a different hook. I think the only concern you could have with doing this is ensuring you do that late enough for the action to have been hooked, it should possible using the plugins_loaded hook(because that runs after plugins have loaded). add_action( ‘plugins_loaded’, ‘juggle_sharethis_action’ ); function juggle_sharethis_action() … Read more