https://wordpress.org/

Ajax call in front-end

In javascript section

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$.ajax({
// ajaxurl is only in back-end
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: {
action: 'my_unique_ajax_action',
param1: 'my query string'
},
success: function(data, textStatus, jqXHR) {
console.log(data);
},
complete: function(jqXHR, textStatus) {
console.log(textStatus);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
});

In your themes/awesome_theme/functions.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (!function_exists('ajax_my_unique_action')) {

function ajax_my_unique_action() {
echo json_encode(array(
'data1' => 'foo',
'data2' => 'bar',
));
header('Content-Type: application/json');
exit;
}

// when user is logged in
add_action('wp_ajax_nopriv_my_unique_ajax_action', 'ajax_my_unique_action' );
// when user is not logged in
add_action( 'wp_ajax_my_unique_ajax_action', 'ajax_my_unique_action' );
}
Reference:

Hide Add New submenu from custom post type

1
2
3
4
5
6
function hide_add_new_custom_type() {
global $submenu;
// replace my_type with the name of your post type
unset($submenu['edit.php?post_type=my_type'][10]);
}
add_action('admin_menu', 'hide_add_new_custom_type');
Reference:

Change admin edit user profile Nickname label

1
2
3
4
5
6
7
function update_profile_label($translation, $original) {
if ( 'Nickname' == $original ) {
return 'Other name';
}
return $translation;
}
add_filter('gettext', array($this, 'update_profile_label'), 10, 2);
Reference:

Add featured image to post

Add the following code to theme’s functions.php

1
add_theme_support( 'post-thumbnails' );
Reference:

Pagination get 404

Make sure the posts_per_page matched with the number in Admin
-> Settings -> Reading -> Blog pages show at most

Reference: