Skip to content

Instantly share code, notes, and snippets.

View sachyya's full-sized avatar
🏠
Working from home

sachyya sachyya

🏠
Working from home
View GitHub Profile
@sachyya
sachyya / loop posts by year
Created October 29, 2015 11:13
This gist is to loop the posts in a specific year in a chunk by year.
//create two custom functions
<?php //retrive years that have posts
function st_get_years_having_posts( $post_type ) {
// get years that have posts
global $wpdb;
$date_query = "SELECT YEAR(post_date) AS year FROM {$wpdb->prefix}posts WHERE post_type = '{$post_type}' AND post_status = 'publish' GROUP BY year DESC";
$years = $wpdb->get_results( $date_query );
return $years;
}
@sachyya
sachyya / custom_wp_is_mobile.php
Created November 24, 2015 07:42
This gist is to use WordPress inbuilt function wp_is_mobile excluding the ipad view port
function custom_wp_is_mobile() {
static $is_mobile;
if ( isset($is_mobile) )
return $is_mobile;
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
$is_mobile = false;
} elseif (
strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
<?php
/**
* Collects all the default theme mods value in an array
* @return array All the default theme mods values
*/
function prefix_get_theme_mods_defaults() {
$defaults = array(
// Site footer options
'option1' => 'value1',
'option2' => 'value2',
su
adduser username sudo
Then reboot.
FTP credentials on plugin installation:
define( 'FS_METHOD', 'direct' );
Pretty permalinks not working:
Edit /etc/apache2/apache2.conf and change:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/**
<?php
* Descriptions on Header Menu
* @link https://codex.wordpress.org/Class_Reference/Walker
*
* @param string $item_output, HTML outputp for the menu item
* @param object $item, menu item object
* @param int $depth, depth in menu structure
* @param object $args, arguments passed to wp_nav_menu()
* @return string $item_output
/***************************************************/
## Social share buttons.
/***************************************************/
function sachyya_social_sharing_buttons() {
global $post;
// Show this on post only.
// Get current page URL
$shortURL = get_permalink();
@sachyya
sachyya / user-customizer-configure
Created February 9, 2017 10:36
This code is to show user to go to specific section to configure that section in a theme.
<?php
if ( current_user_can( 'customize' ) ) { ?>
<div class="message">
<p><?php _e( 'There are no pages available to display.', 'textdomain' ); ?></p>
<p><?php printf(
__( 'These pages can be set in the <a href="%s">customizer</a>.', 'textdomain' ),
admin_url( 'customize.php?autofocus[control]=showcase' )
); ?>
</p>