Created
March 27, 2018 11:50
-
-
Save omartdev/185bdf920ca582fac67c3678ef24f829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get thumbanil url | |
function get_thumbanil_url($post,$image_size){ | |
if ( has_post_thumbnail($post->ID) ) { | |
$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),$image_size, true ); | |
$thumb_url = $thumbnail_url[0]; | |
} | |
else{ | |
$thumb_url = ''; | |
} | |
return $thumb_url; | |
} | |
//<?php echo get_thumbanil_url($post,'full'); ?> | |
---------------------------------------------------------- | |
// allow span and other tags | |
function override_mce_options($initArray) { | |
$opts = '*[*]'; | |
$initArray['valid_elements'] = $opts; | |
$initArray['extended_valid_elements'] = $opts; | |
return $initArray; | |
} | |
add_filter('tiny_mce_before_init', 'override_mce_options'); | |
-------------------------------------------------------------- | |
// get category name and href | |
function get_cat_name_href($post_id){ | |
$cats = array(); | |
foreach (get_the_category($post_id) as $c) { | |
$cat = get_category($c); | |
$wurl = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $cat->name ) ) . '">' . esc_html( $cat->name ) . '</a>'; | |
array_push($cats, $wurl); | |
} | |
if (sizeOf($cats) > 0) { | |
$post_categories = implode(', ', $cats); | |
} else { | |
$post_categories = ''; | |
} | |
return $post_categories; | |
} | |
------------------------------------------------------------------ | |
// camelCase | |
function camelCase($str, array $noStrip = []) | |
{ | |
// non-alpha and non-numeric characters become spaces | |
$str = preg_replace('/[^a-z0-9' . implode("", $noStrip) . ']+/i', ' ', $str); | |
$str = trim($str); | |
// uppercase the first character of each word | |
$str = ucwords($str); | |
$str = str_replace(" ", "", $str); | |
$str = lcfirst($str); | |
return $str; | |
} | |
-------------------------------------------------------------------- | |
// get Next previous link | |
function getNextPreviousUrl() | |
{ | |
$prev_post = get_previous_post(); | |
$next_url = ''; $next_title = ''; $prev_title = ''; $prev_url = ''; | |
if($prev_post) { | |
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title)); | |
$prev_title = !empty($prev_title) ? $prev_title : ''; | |
$prev_url = get_permalink($prev_post->ID) ; | |
$prev_url = !empty($prev_url) ? $prev_url : ''; | |
} | |
$next_post = get_next_post(); | |
if($next_post) { | |
$next_title = strip_tags(str_replace('"', '', $next_post->post_title)); | |
$next_title = !empty($next_title) ? $next_title : ''; | |
$next_url = get_permalink($next_post->ID); | |
$next_url = !empty($next_url) ? $next_url : ''; | |
} | |
return([$next_url, $next_title, $prev_title, $prev_url]); | |
} | |
//list($next_url, $next_title, $prev_title, $prev_url) = getNextPreviousUrl(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment