Tags » PHP 2

Remove Admin Dashboard Widget

function remove_dashboard_widgets(){
global$wp_meta_boxes;
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_plugins’]);
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_recent_comments’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_primary’]);
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_incoming_links’]);
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_right_now’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_secondary’]);
}

add_action(‘wp_dashboard_setup’, ‘remove_dashboard_widgets’);

//Removing Menu Items

function remove_menu_items() {
global $menu;
$restricted = array(__(‘Links’), __(‘Media’),
(‘Plugins’), (‘Tools’), __(‘Users’)); 28 more words

Wordpress

Total Search Result Count

<?php
/* Search Count */
$allsearch = &new WP_Query(“s=$s&showposts=-1″);
$key = wp_specialchars($s, 1);
$count = $allsearch->post_count; _e(”);
//_e(‘<span class=”search-terms”>’);
//echo $key; _e(‘</span>’);
//_e(‘ &mdash; ‘); 40 more words

Wordpress

Google Like Pagination

function pagination($pages = ”, $range = 4)
{
$showitems = ($range * 2)+1;

global $paged;
if(empty($paged)) $paged = 1;

if($pages == ”)
{
global $wp_query; 100 more words

Wordpress

Get The Feature Image Url

$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’, false );
echo $src[0]; // the url of featured image

Wordpress

Show Excerpt length Depends on Feature Image

add_filter(‘get_the_excerpt’, ‘do_my_shortcode_in_excerpt’);
function do_my_shortcode_in_excerpt($excerpt) {
if ( has_post_thumbnail() ) {
return do_shortcode(wp_trim_words(get_the_content(), 55));
}
else{
return do_shortcode(wp_trim_words(get_the_content(), 100));
}
}

Wordpress

Accordian Slider with Custom Post

function tiptrick_shortcode($atts, $content){
extract (shortcode_atts( array( ‘posts’ => 4, ‘category_slug’ => “tipstricks-default-category”,

), $atts ));
global $post;

$args=array( ‘post_type’=>’tiptrick’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => $posts, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘caller_get_posts’=> 1, ‘tiptrick_cat’=> $category_slug, 161 more words

Wordpress

Search For a Custom Post Type Only

<form role=”search” action=”<?php echo site_url(‘/’); ?>” method=”get” id=”searchform”>
<input type=”text” name=”s” placeholder=”Search Portfolio”/>
<input type=”hidden” name=”post_type” value=”myportfolio” />
<input type=”submit” alt=”Search” value=”Search” />
</form>

Wordpress