How to get the post slug

basename( get_permalink($id) );

If you have access to the data through the global variable $post you can simply use $post->post_name;

1
2
3
4
5
6
7
8
9
10
11
12
function get_slug( $id = NULL ) {
 
   if( $id != NULL ) {
     return basename( get_permalink($id) );
   }
 
   global $post;
   if( empty($post) ) return;
 
   return $post->post_name;
 
}

In other cases maybe you don’t have the $id and you are trying to get the $post var to early like in an init hook, in this case you can try using url_to_postid to retrieve the ID and then get the slug.

So the full function would be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function get_slug( $id = NULL ) {
 
  if( $id == NULL ){
 
    global $post;
 
   if( !empty( $post )) {
        $id = $post->ID;
    } else {
        $id = url_to_postid( "http://".$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    }
 
  } // if $id NULL
 
  return basename( get_permalink($id) );
}

Set up Tiled Galleries without installing Jetpack

tiled-gallery-banner

There is a lot of demand on having some of the functionality that Jetpack offers without having to install the Jetpack plugin.
You can find this plugin this plugin, by ThemePacific, useful to have a tiled gallery carousel, it’s pretty neat, does exactly what the Tiled Gallery in Jetpack does.

The options are:

  • Enable or disable the carousel.
  • Background color when displaying the carousel.
  • Display the photo metadata on the carousel.
  • Select the different gallery styles: Thumbnail Grid, Tiled Mosaic, Square Tiles and Circles.
  • And the option to set the galleries to Tiled Mosaic as default.

Check it out on the wordpress.org plugin repository.

Contact Form 7, save submited data in the database

Create a table to store the data in the database.

CREATE TABLE `wp_tps_forms` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `form` varchar(100) NOT NULL DEFAULT '',
  `data` text NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
add_action('wpcf7_before_send_mail', 'save_form' );
 
function save_form( $wpcf7 ) {
   global $wpdb;
 
   /*
    Note: since version 3.9 Contact Form 7 has removed $wpcf7->posted_data
    and now we use an API to get the posted data.
   */
 
   $submission = WPCF7_Submission::get_instance();
 
   if ( $submission ) {
 
       $submited = array();
       $submited['title'] = $wpcf7->title();
       $submited['posted_data'] = $submission->get_posted_data();
 
    }
 
     $data = array(
   		'name'  => $submited['posted_data']['name'],
   		'email' => $submited['posted_data']['email']
   	     );
 
     $wpdb->insert( $wpdb->prefix . 'tps_forms', 
		    array( 
                          'form'  => $submited['title'], 
			   'data' => serialize( $data ),
			   'date' => date('Y-m-d H:i:s')
			)
		);
}

Contact Form 7, change texts on email body

For example, you receive a POST ID as a parameter, and you want to add the title of the post in the body of the email sent by Contact Form 7.
You can add the text [my_post_id] in the body of the form configuration from the admin dashboard.
Then replace it with the data you need, in this case the title, using the filer wpcf7_mail_components.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
add_filter( 'wpcf7_mail_components', 'custom_mail_components');
 
function custom_mail_components($wpcf7_data, $form = null) {
 
     if( isset( $_GET['my_post_id'] ) ){
 
        $post = get_post( $_GET['my_post_id'], ARRAY_A );
 
        $str = $post['post_title']. ' ' . get_permalink( $_GET['my_post_id'] ) ;
	$wpcf7_data['body'] = str_replace('[my_post_id]', $str , $wpcf7_data['body'] );
     }
 
     return $wpcf7_data;
}

Move meta box after the title

First register your meta box with $context ‘advanced’ and $priority ‘high’

1
add_meta_box( 'my_metabox_id', 'my_metabox_title', 'my_callback', 'post_type', 'advanced', 'high' );

Then use the hook edit_form_after_title to print the metaboxes with do_meta_boxes function and unset them so they don’t display twice. It will move all metaboxes on the screen with an advanced context.

1
2
3
4
5
6
7
8
add_action('edit_form_after_title',  array( $this, 'move_metabox_after_title' ) );
 
function move_metabox_after_title () {
    global $post, $wp_meta_boxes;
 
    do_meta_boxes( get_current_screen(), 'advanced', $post );
    unset( $wp_meta_boxes[get_post_type( $post )]['advanced'] );
}

Source found here.

Simple Cookie Notification Bar

banner-772x250
As the name says, this plugin displays a notification bar at the bottom of your page informing about the use of cookies, responsive design.
A settings page easy to use and configure where you can change all the texts, colors and font size.

By default the plugin will display an “Accept” button to hide the notification, but you can also add a “More Information” button with any link.
It will cover you basic needs for this kind of notification.

You can download it for free on the wordpress.org plugin repository or directly clicking on the Download button on this page. And if you are happy with the plugin you can donate from the button bellow. Thanks!

Download Plugin




 

screenshot-1screenshot-2

Add Walker_Nav_Menu extension with Genesis

1
2
3
4
5
6
7
8
9
10
11
12
// filer wp_nav_menu_args to add the custom walker to wp_nav_menu(), used by genesis_do_nav()
add_filter( 'wp_nav_menu_args', 'my_navigation_walker' );
 
function my_navigation_walker ( $args ){
    if( isset( $args['menu_class'] ) && 'menu genesis-nav-menu menu-primary' === $args['menu_class'] ) {
	if( class_exists( 'My_Navigation' ) ) {
		$args['walker'] = new My_Navigation(); 
	}
    }
 
    return $args;
 }

Source found here

WP Migrate DB

By deliciousbrains.com, with this plugin you can migrate your database from one WordPress installation to another in just a click, depending on how large your database is it will take longer or not to generate the database dump, but all in all it’s really quick, and definitely this is one of those plugins that I can’t live without.

I highly recommend it, it works beautifully! You can download it for free on the wordpress.org repository. It also has a premium version, which I have never tested as I really haven’t had  the necessity yet to purchase it, but checkout the futures on their webpage.

Create Sitemap HTML Page

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php 
 
 /*
 Template Name: Sitemap Page
 */
 
get_header();
 
	/* PAGES
	----------------------------------------------*/
 
	// Get the navigation items to display the same order and save them in array to exclude later
 
	$items = wp_get_nav_menu_items( 'my menu id' );
	$exclude_pages = get_the_ID(); // to not display current sitemap page
 
	echo '<ul>';
 
 	foreach( $items as $item )  {
 
                $class = '';
		$exclude_pages .= ',' . $item->object_id;
 
		if( $item->menu_item_parent != 0) {
			$class = ' class="sitemap-item-child"';
		}
 
		?>
			<li<?php echo $class ?>>
				<a href=""><?php echo $item->title; ?></a>
			</li>
 
		<?php
 
	}
 
	// List the rest of the pages that are not in the navigation
	wp_list_pages(
			 array(
			   'exclude' => $exclude_pages,
			   'title_li' => '',
			 )
		);
 
	echo '</ul>';
 
	/* CUSTOM POST TYPES 
	----------------------------------------------*/
 
	foreach( get_post_types( array('public' => true) ) as $post_type ) {
 
	  if ( in_array( $post_type, array('post','page','attachment') ) ) continue;
 
	  $item = get_post_type_object( $post_type );
 
	  echo '<h2>'.$item->labels->name.'</h2>';
 
	  $args = array(
		'post_type' => $post_type,
		'posts_per_page'    => -1
	  );
 
	  $query = new WP_Query( $args );
 
	  echo '<ul>';
 
		while ( $query->have_posts() ) {
 
			$query->the_post();
			echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
 
		}
 
	  echo '</ul>';
 
	}
 
 
get_footer();

How to change Genesis breadcrumbs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
add_filter('genesis_breadcrumb_args', 'custom_breadcrumbs_labels');
 
function custom_breadcrumbs_labels( $args ) {
  $args['labels']['prefix'] = '';
  return $args;
}
 
/*
Default arguments:
 
$this->args = array(
		'home'                    => __( 'Home', 'genesis' ),
		'sep'                     => 
                'list_sep'                => ', ',
		'prefix'                  => '<div class="breadcrumb">',
		'suffix'                  => '</div>',
		'heirarchial_attachments' => true,
		'heirarchial_categories'  => true,
		'labels' => array(
				'prefix'    => __( 'You are here: ', 'genesis' ),
				'author'    => __( 'Archives for ', 'genesis' ),
				'category'  => __( 'Archives for ', 'genesis' ),
				'tag'       => __( 'Archives for ', 'genesis' ),
				'date'      => __( 'Archives for ', 'genesis' ),
				'search'    => __( 'Search for ', 'genesis' ),
				'tax'       => __( 'Archives for ', 'genesis' ),
				'post_type' => __( 'Archives for ', 'genesis' ),
				'404'       => __( 'Not found: ', 'genesis' ) 
                            )
                  );
 
*/