Skip to content

Instantly share code, notes, and snippets.

@ajithrn
ajithrn / short_content.php
Last active August 29, 2015 13:56
Wordpress: short_content
<?php
/**
* short_content generator
* @param string $mycontent content string
* @param string $after
* @param int $length
* @return string
*/
function short_content( $mycontent, $after = '', $length ) {
@ajithrn
ajithrn / breadcrumbs.php
Created February 22, 2014 08:48
Wordpress: breadcrumbs
<?php
/**
* only works in pages, no categories support
* */
echo '<ul>';
if ( is_page() && $post->post_parent ): // checking if the page has parent
$parent_id = $post->post_parent;
$breadcrumbs = array();
@ajithrn
ajithrn / acf-option-page.php
Last active August 29, 2015 13:56
Wordpress: acf option page customization
<?php
/**
* ======== acf option page customization ========
* @param [type] $settings
* @return [type]
*/
function my_acf_options_page_settings( $settings )
{
$settings['title'] = 'Page Title';
$settings['menu'] = 'Menu Title';
@ajithrn
ajithrn / wp-query.php
Last active August 29, 2015 13:56
Wordpress: wp query
<?php
/** Wordpress general query
* http://codex.wordpress.org/Class_Reference/WP_Query
* */
// WP_Query arguments
$custom_args = array ( 'post_type' => 'custom_post', 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => '5', 'order' => 'DESC', 'orderby' => 'date', );
// The Query
$custom_query = new WP_Query( $custom_args );
@ajithrn
ajithrn / prepend-www
Created February 25, 2014 16:09
htaccess: prepend www
#add www.infront of urls
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
@ajithrn
ajithrn / top-parent-id.php
Last active August 29, 2015 13:57
Wprdpress: Top Parent page id
<?php
if ($post->post_parent) :
$ancestors = get_post_ancestors($post->ID); //get all parent post ids in an array
$root = count($ancestors)-1; //find the count
$parent = $ancestors[$root]; //get top parent id
else:
@ajithrn
ajithrn / wp-custom-admin-columns.php
Last active August 29, 2015 13:57
Wordpress: custom admin columns sorting
<?php
/**
* custom admin columns for custom-post-type , and sorting
*
* custom_post_type: enter cutom post type as function name
* custom-post-type: enter your custom post here
* custom_column: enter your custom colum id
* custom_column1: enter your custom colum id
* CustomColumnName: enter your custom column name
* custom_meta: enter custom meta
@ajithrn
ajithrn / bmq.css
Created March 31, 2014 19:08
CSS: Bootstrap 3 Media Queries
/*==================================================
= Bootstrap 3 Media Queries =
==================================================*/
/*========== Mobile First Method ==========*/
/* Custom, iPhone Retina */
@media only screen and (min-width : 320px) {
@ajithrn
ajithrn / media-custom-images.php
Last active August 29, 2015 14:00
Wordpress: custom media image sizes
<?php
// Add new image sizes to media editor
function media_custom_image_sizes( $image_sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $image_sizes;
@ajithrn
ajithrn / favicon.php
Last active August 29, 2015 14:03
Wordpress: custom favicon
/**
** Function to add custom favicon in wordpress blog
**/
function add_favicon() {
$favicon_path = get_template_directory_uri() . '/assets/img/favicon.ico';
echo '<link rel="shortcut icon" href="' . $favicon_path . '" />';
}
add_action( 'wp_head', 'add_favicon' ); //front end
add_action( 'admin_head', 'add_favicon' ); //admin end