Slugs as breadcrumbs for Pages

Ok, problem solved. I´ll add the script below. Hope it´s useful for someone. if ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ){ echo “<li> &raquo; “.ucwords(str_replace(“-“, ” “, $post->post_name)).”</li>”; } else { $title = the_title(”,”, FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor … Read more

How do you permanently remove default rewrite rules from the wp_options table?

Rather than modifying stored rules it would be more reliable to modify rules before they are stored. flush_rewrite_rules() calls WP_Rewrite->flush_rules() WP_Rewrite->wp_rewrite_rules() WP_Rewrite->rewrite_rules() Inside last there are fitting hooks to modify rules (after which result they will be saved as usual on each flush): do_action_ref_array(‘generate_rewrite_rules’, array(&$this)); $this->rules = apply_filters(‘rewrite_rules_array’, $this->rules);

Why do I get Fatal error: Call to undefined function get_most_recent_post_of_user()?

get_most_recent_post_of_user() is for multisite installs to get the most recent post of the user from each blog. Here is a comparable function you can use that will return the post object of the defined users most recent post. function wpse_get_user_recent( $user ) { global $wpdb; $recent = $wpdb->get_row( $wpdb->prepare(“SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author … Read more

How to prevent deleting of comments when deleting a post

To prevent the comment deletion hook into before_delete_post, and filter the query for associated comments so the deletion routine cannot find and delete those. PHP 5.3 required: add_action( ‘before_delete_post’, function( $post_id ) { add_filter( ‘query’, function( $query ) use ( $post_id ) { $find = ‘WHERE comment_parent=”; FALSE !== strpos( $query, $find . $post_id ) … Read more

How to display error messages using WP_Error class?

With that in functions.php you’d probably have to declare $error to be global like so : if (‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty($_POST[‘action’]) && $_POST[‘action’] == ‘registration’) { global $error; $error = new WP_Error(); // the rest of your code And then do global $error; again on your registration page before trying to use it. But … Read more

Create new user without password

Current versions of WP allow creation of a user without creating a password. Just leave password area blank, and verify no password if prompted. But, best practice might be to create user with a random password, but not tell the user the password. Have them do the ‘lost password’ thing to set up their own … Read more

How to use get_media_embedded_in_content function

The get_media_embedded_in_content() function is a handy helper function, though it doesn’t seem to be used in the core (ver. 4.2.2). Regular expression: To understand the get_media_embedded_in_content() function, we must understand the following regular expression: #<(?P<tag>video|audio|object|embed|iframe)[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)# There are many online regular-expression tools to help us with that. Like this one: Debuggex demo We note that it’s … Read more