Skip to content

Instantly share code, notes, and snippets.

View Tsunamijaan's full-sized avatar

Tariqul Islam Tsunamijaan

  • Coder Team IT
  • Rajshahi, Bangladesh
View GitHub Profile
@Tsunamijaan
Tsunamijaan / Add a Special Class for the First Post in the Loop
Created January 5, 2019 09:07
Add a Special Class for the First Post in the Loop
add_filter( 'post_class', 'post_class_example' );
function post_class_example( $classes ) {
global $wp_query;
if ( 0 == $wp_query->current_post ) {
$classes[] = 'first-post';
}
return $classes;
}
@Tsunamijaan
Tsunamijaan / To Remove the URL Field in the Comment Form
Created January 5, 2019 09:07
To Remove the URL Field in the Comment Form
add_filter( 'comment_form_default_fields', 'comment_form_default_fields_example' );
function comment_form_default_fields_example( $fields ) {
unset( $fields['url'] );
return $fields;
}
@Tsunamijaan
Tsunamijaan / To Change the Default “Lost Password” Messages
Created January 5, 2019 09:06
To Change the Default “Lost Password” Messages
add_filter( 'login_message', 'login_message_example' );
function login_message_example( $message ) {
$action = $_REQUEST['action'];
if( $action == 'lostpassword' ) {
$message = '<p class="message">Enter your email address, then check your inbox for the "reset password" link!</p>';
return $message;
}
return;
}
@Tsunamijaan
Tsunamijaan / How to Add a Custom Admin Menu for plugin
Created January 5, 2019 09:05
How to Add a Custom Admin Menu for plugin
add_action('admin_menu', 'myplugin_menu_pages');
function myplugin_menu_pages() {
// Add the top-level admin menu
$page_title = 'My Plugin Settings';
$menu_title = 'My Plugin';
$capability = 'manage_options';
$menu_slug = 'myplugin-settings';
$function = 'myplugin_settings';
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function);
@Tsunamijaan
Tsunamijaan / Options Page for a Plugin under Settings
Created January 5, 2019 09:05
Options Page for a Plugin under Settings
============Register Settings For a Plugin=======
function myplugin_register_settings() {
add_option( 'myplugin_option_name', 'This is my option value.');
register_setting( 'myplugin_options_group', 'myplugin_option_name', 'myplugin_callback' );
}
add_action( 'admin_init', 'myplugin_register_settings' );
============Creating an Options Page===========
@Tsunamijaan
Tsunamijaan / To Create a Simple WordPress Theme Settings Page
Created January 5, 2019 09:03
To Create a Simple WordPress Theme Settings Page
Step 1 – Registering the Settings Page======
//Admin Panel Settings
//Register Settings Function
function theme_settings_init(){
register_setting( 'theme_settings', 'theme_settings' );
}
//Add settings to page menu
function add_settings_page() {
@Tsunamijaan
Tsunamijaan / To Automatically Create Meta Description From Content
Created January 5, 2019 09:00
To Automatically Create Meta Description From Content
function create_meta_desc() {
global $post;
if (!is_single()) { return; }
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($meta);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 125);
echo "<meta name='description' content='$meta' />";
}
add_action('wp_head', 'create_meta_desc');
@Tsunamijaan
Tsunamijaan / To Display Breadcrumbs
Created January 5, 2019 08:59
To Display Breadcrumbs
function the_breadcrumb() {
if (!is_home()) {
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo "</a> ";
if (is_category() || is_single()) {
the_category('title_li=');
if (is_single()) {
@Tsunamijaan
Tsunamijaan / Option tree list item usages
Created January 5, 2019 08:59
Option tree list item usages
To create option tree list item metabox===
array(
'label' => 'Team Social',
'id' => 'team_links',
'type' => 'list-item',
'section' => 'social_icons_setting',
'settings' => array(
array(
@Tsunamijaan
Tsunamijaan / If current user
Created January 5, 2019 08:58
If current user
<?php
global $current_user;
get_currentuserinfo();
if ($current_user->ID == '') {
//show nothing to user
}
else {
//write code to show menu here
}