Search This Blog

Friday 1 March 2019

Add woocommerce custom product tabs.

Add in your functions.php

add_filter( 'woocommerce_product_tabs', 'woocommerce_custom_product_tabs' );

function woocommerce_custom_product_tabs( $tabs ) {

 $tabs['courses_tab'] = array(
        'title'     => __( 'Courses', 'woocommerce' ), //Tab title
        'priority'  => 100, // Tab priority
        'callback'  => 'courses_tab_content' //callback function
    );
return $tabs;

  }

//callback function
function courses_tab_content() {
    echo '<h2>Courses</h2>';
    echo '<p>Courses tab.</p>';
}


Sunday 24 February 2019

Get Post By Meta value in wordpress.

function getPostByMetavalue(){
// the meta_key 'diplay_on_homepage' with the meta_value 'true'
$args = array(
    'post_type'        => 'product', //your custom post type name
    'meta_key'         => '_regular_price', //Meta key what do you want to search by key.
    'meta_value'       => 50, // Meta Values
'posts_per_page'   => -1 // Post per page -1 means show all post you can add your choice like 10 or 5...
);
$query = new WP_Query( $args );
echo "<pre>";print_r($query);echo "</pre>";
}
add_shortcode('getPostByMetavalue_short','getPostByMetavalue');

Sunday 15 April 2018

Create custom widget area in wordpress.

If you are familiar with Wordpress, then you can add easily widget area into the dashboard.

1. Go with an activated WordPress theme, open functions.php and add below code.

<?php

function custom_widgets() {

register_sidebar( array(
'name'          => 'News Sidebar',
'id'            => 'news_sidebar',
'before_widget' => '<div>',
'after_widget'  => '</div>',
'before_title'  => '<h2>',
'after_title'   => '</h2>',
) );

}
add_action( 'init', 'custom_widgets' );
?>

Now ready, go to dashboard widget area drag text or any widget.

2. Call widget where you want to show.

<?php dynamic_sidebar('news_sidebar'); ?>

Saturday 24 March 2018

Insert data through ajax into MySql database.

1. Create form.php and copy below code into file.

<script type="text/javascript">

$(document).ready(function(){
$('#submit').click(function(){
var name= $('#name').val();
var email= $('#email').val();
var sdatatring='name1='+ name +'&email1='+ email;
$.ajax({
type:"POST",
  url:"insert.php",
  data:sdatatring,
  cache: false,
  success:function(result){
  alert(result);

  }});


});

});
</script>
  <form method="post" action="" name="frm">
  Name:<input type="text" name="name" id="name" value=""><br>
  Email:<input type="text" name="email" id="email" value=""><br>
  <input type="button" name="submt" id="submit" value="submit" />
 
  </form>

 2. Create insert.php and copy below code into file.
 <?php
print_r($_POST);
$con=mysql_connect("localhost","root","");
mysql_select_db('dbname');
mysql_query('insert into tablename('colname')values(value)');
 ?>
Note:You need to include jQuery  library in form.php.

Friday 9 March 2018

bloginfo() function in wordpress.


Displays information about the current site.



Get data about your site, for the most part assembled from the data you supply in your User Profile and General Settings WordPress Administration Screens. It can be utilized anyplace inside a layout record. This dependably prints an outcome to the program. If you need the values for use in PHP, use bloginfo() function.
bloginfo() function not a PHP function, it's created by WordPress.


Example:

"name" – Get the "Site Title", This data is retrieved from the "blogname" record in the wp_options table.
<?php echo bloginfo('name'); ?>

"description" – Get the "Tagline", This data is retrieved from the "blogdescription" record in the wp_options table.
<?php echo bloginfo('description'); ?>

also you can use (wpurl,url,admin_email,charset,version,html_type,text_direction,language,stylesheet_url,stylesheet_directory,template_url,pingback_url,atom_url,rdf_url,rss_url,rss2_url,comments_atom_url,rdf_url,rss_url,rss2_url,comments_atom_url,comments_rss2_url)

"siteurl" – Deprecated since version 2.2. Echo home_url(), or use bloginfo("url").
"home" – Deprecated since version 2.2. Echo home_url(), or use bloginfo("url").

What is WordPress Memory Limit Error?

WordPress is composed in PHP, which is a server-side programming dialect. Each site needs a WordPress facilitating server for it to work legitimately.

Web servers are much the same as some other PC. They require memory to effectively run different applications in the meantime. Server managers apportion particular memory size to various applications including PHP.

At the point when your WordPress code requires more memory than the default designated memory, you get the opportunity to see this mistake.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home4/example/public_html/wp-includes/plugin.php on line 356



By default, WordPress automatically tries to increase PHP memory limit if it is less than 64MB. However, 64MB is often not high enough.

Having said that, let’s see how to easily increase PHP memory limit in WordPress to avoid memory exhausted error.

Increase PHP Memory Limit in WordPress
First you need to edit the wp-config.php file on your WordPress site. It is located in your WordPress site’s root folder, and you will need to use an FTP client or file manager in your web hosting control panel.

Next, you need to paste this code in wp-config.php file just before the line that says ‘That’s all, stop editing! Happy blogging.’

define( 'WP_MEMORY_LIMIT', '256M' );
This code tells WordPress to increase the PHP memory limit to 256MB.

Once you are done, you need to save your changes and upload your wp-config.php file back to your server.

Friday 23 February 2018

Get post thumbnail by post id ("thumbnail,medium,large,full") in wordpress.

Get post thumbnail by post id ("thumbnail,medium,large,full").

<?php
// without parameter -> Post Thumbnail (as set by theme using set_post_thumbnail_size())
$postId=12;
get_the_post_thumbnail($postId );                 

get_the_post_thumbnail( $postId, 'thumbnail' );      // Thumbnail (Note: different to Post Thumbnail)
get_the_post_thumbnail( $postId, 'medium' );         // Medium resolution
get_the_post_thumbnail( $postId, 'large' );          // Large resolution
get_the_post_thumbnail( $postId, 'full' );           // Original resolution

get_the_post_thumbnail( $postId, array( 100, 100) ); // Other resolutions

You can also give Post Thumbnails their own class:
// Give the Post Thumbnail a class "alignleft".
echo get_the_post_thumbnail( $post_id, 'thumbnail', array( 'class' => 'alignleft' ) );