Skip to content

Instantly share code, notes, and snippets.

View alokstha1's full-sized avatar

Alok Shrestha alokstha1

View GitHub Profile
@alokstha1
alokstha1 / archive.php
Created March 19, 2015 06:42
Pagination on archive.php, category.php, taxonomy.php on wordpress
<?php
if(have_posts()){
while ( have_posts() ) : the_post();
the_title();
endwhile;
}
previous_posts_link();
next_posts_link();
@alokstha1
alokstha1 / custom_sql.sql
Created August 27, 2015 09:09
Select sql from two table LIKE on first table
SELECT * from table1 as t1 LEFT JOIN table2 as t2 ON t2.foreign_key = t1.prmary_key WHERE t1.column_name LIKE '%{variable}%'
@alokstha1
alokstha1 / functions.php
Last active September 12, 2015 05:35
buddypress customize user activation email to admin
<?php
add_filter( 'bp_core_sent_user_validation_email', 'custom_buddypress_activation_message', 1, 4 );
function custom_buddypress_activation_message( $subject, $message, $user_id, $meta ) {
$user_meta = get_user_meta($user_id, 'activation_key', OBJECT);
$subject = '[SIEBA] Activate Users';
$message .= 'Activate User With';
$message .= 'Username: '.$_POST['signup_username'].'<br>';
$message .= 'Email: '.$_POST['signup_email'].'<br>';
@alokstha1
alokstha1 / functions.php
Created September 12, 2015 05:44
Registration and login wordpress
<?php
/* Registration form _shrtcode*/
function registration_form( $atts ) {
if ( !is_user_logged_in()) {
ob_start();
?>
<div class="col">
<h2>Registration Form</h2>
@alokstha1
alokstha1 / functions.php
Last active September 15, 2015 03:58
BuddyPress Profile navigation
<?php
function profile_nav_item() {
global $bp;
bp_core_new_subnav_item(
array(
'name' => __( 'User Profile', 'buddypress' ),
'slug' => 'user-profile',
'position' => 10,
'screen_function' => 'user_listingsdisplay',
@alokstha1
alokstha1 / functions.php
Created September 29, 2015 04:12
Wordpress widget to get posts
<?php
function my_widget() {
register_widget('Widget_Name');
}
add_action('widgets_init', 'my_widget');
/**
@alokstha1
alokstha1 / script.js
Created November 5, 2015 10:25
Get only the Upload Files Tab of Wordpress Media uploader
<script type="text/javascript">
jQuery(document).ready(function(){
wp.media.controller.Library.prototype.defaults.contentUserSetting=false;
});
</script>
@alokstha1
alokstha1 / install-wordpress-standard.txt
Created November 18, 2015 12:05
Install PHPCS with WordPress Coding Standard with Sublime Text 3
#optional part to install wordpress coding standards
git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
# tell phpcs about the wordpress coding standards
cd ~/bin/phpcs
scripts/phpcs --config-set installed_paths ../wpcs
# we probably want to ignore the space indenting on the files
vim ~/bin/ruleset.xml
@alokstha1
alokstha1 / functions.php
Created February 23, 2016 08:53
Wp Breadcrumb for custom post types too
<?php
function custom_breadcrumbs() {
// Settings
$separator = '&gt;';
$breadcrums_id = 'breadcrumbs';
$breadcrums_class = 'breadcrumbs';
$home_title = 'Home';
// If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat)
@alokstha1
alokstha1 / functions.php
Created March 1, 2016 10:52
Wp Subtitle
<?php
add_action( 'edit_form_after_title', 'cpm_add_subtitle_field');
function cpm_add_subtitle_field() {
global $post;
echo '<input type="hidden" name="wp_noncename" id="wp_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
echo '<div id="subtitlediv" class="top">';
echo '<div id="subtitlewrap">';
echo '<input type="text" id="cpmsubtitle" name="cpm_subtitle" value="' . esc_attr( get_post_meta( $post->ID, 'sub_title_meta', true ) ) . '" autocomplete="off" placeholder="' . esc_attr( __( 'Enter subtitle here' ) ) . '" />';
echo '</div></div>';
}