Posts

Showing posts with the label WordPress

2021 Top 4 Best Upcoming Flagship Smartphones : which are the best mobile phones for you..?

Image
  Hi here are the top 8 best upcoming flagship smartphones of 2021 with high-end level features improved cameras stunning design and many other next-generation technologies will be applied that you will really enjoy also the price and the release date of the smartphones are discussed. Number four Asus Zenfone 8 Number three OnePlus 9 Number two Huawei P50 Number one Apple iPad Pro 12.9

Creating SEO friendly URLs with the merger of Wordpress and CodeIgniter

Objective: Suppose you are required to create SEO friendly URLs with the merger of WP and CI, WP as front-end and CI as admin panel. You are adding projects with CI and showing detail of that project with WP. Steps: Code in controller (project.php) // create user friendly url string as per project name $pro_name = “new project name”; $pro_url = strtolower(str_replace(' ','-',trim($pro_name))); // insert in to wp_posts table $post = array( 'post_title' => $pro_name, 'post_name' => $pro_url, 'post_type' => 'page' ); $post_id = $this->utility_model->set('wp_posts', $post); // insert in to wp_postmeta table $postmeta = array( 'post_id' => $post_id, 'meta_key' => '_wp_page_template', 'meta_value' => 'project-detail.php' ); $this->utility_model->set('wp_postmeta', $postmeta); /* insert in to

Add Class for Image in Content

The given PHP example adds a class to the standard classes in Images in Posts/Pages in WordPress. <?php function bb_add_image_class($class){ $class .= ' scale-with-grid'; return $class; } add_filter('get_image_tag_class','bb_add_image_class'); ?>

Get URL Thumbnail

The given PHP example get the thumbnail URL in WordPress. <?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 140,140 ), false, '' ); echo $src[0]; ?>

Change Login Logo and Login Link

The given PHP example helps you to change the login logo and the login link into WordPress. <?php function custom_loginlogo() { echo ' '; } add_action('login_head', 'custom_loginlogo'); add_filter( 'login_headerurl', 'custom_loginlogo_url' ); function custom_loginlogo_url($url) { return 'http://www.wpbeginner.com'; } ?>

Hide The Front-End Dashboard Bar

The given PHP example helps you to hide the Front-End dashboard bar from WordPress. Place this in your index.php before wp_footer() is called. <?php show_admin_bar( false ); ?>

Get the First Image from the Post and Display it.

The given PHP example allows you to automatically get the first image from the current post, and display it into WordPress. <?php function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/ /i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img; } echo catch_that_image(); ?>

Display Post Views Within Admin Post Columns

The given PHP example will display the post views within admin post columns into WordPress. <php add_filter('manage_posts_columns', 'posts_column_views'); add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2); function posts_column_views($defaults){ $defaults['post_views'] = __('Views'); return $defaults; } function posts_custom_column_views($column_name, $id){ if($column_name === 'post_views'){ echo getPostViews(get_the_ID()); } } ?>

Filter Category

The given PHP example filter out a category from your WordPress. Add this code to your functions.php file. <?php function exclude_cat(){         if(is_home) {                 $query-> set('cat','-312');         }         return $query; } add_filter('pre_get_posts','exclude_cat'); ?>