Skip to main content

Posts

Showing posts with the label Wordpress

How To Create Shortcodes In WordPress

We can create own shortcode by using its predified hooks add_shortcode( 'hello-world', 'techsudhir_hello_world_shortcode' ); 1. Write the Shortcode Function Write a function with a unique name, which will execute the code you’d like the shortcode to trigger: function techsudhir_hello_world_shortcode() {    return 'Hello world!'; } Example: [hello-world] If we were to use this function normally, it would return Hello world! as a string 2. Shortcode function with parameters function techsudhir_hello_world_shortcode( $atts ) {    $a = shortcode_atts( array(       'name' => 'world'    ), $atts );    return 'Hello ' . $a['name'] . !'; } Example: [hello-world name="Sudhir"] You can also call shortcode function in PHP using do_shortcode function Example: do_shortcode('[hello-world]');

How to get custom image size url in Wordpress

Here are simple way to get custom image from URL $imgUrl = 'http://localhost/wptest/wp-content/themes/sydney/images/header.jpg';   global $wpdb; $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $imgUrl )); $image_id = $attachment[0]; $thumbnail_url = wp_get_attachment_image_src($image_id, array('615','440'), true );

How to Add Next Previous links to The Event Calendar

Add Next/Previous links to The Event Calendar Wordpress Plugin Add code to your child theme’s functions.php file /**  * Allows visitors to page forward/backwards in any direction within month view */ if ( class_exists( 'Tribe__Events__Main' ) ) { class ContinualMonthViewPagination {     public function __construct() {         add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) );         add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) );     }     public function next_month() {         $url = tribe_get_next_month_link();         $text = tribe_get_next_month_text();         $date = Tribe__Events__Main::instance()->nextMonth( tribe_get_month_view_date() );         return '<a data-month="' . $date . '" href="' . $url . '" rel="next"...

How to use registered post type Hook

How to use registered_post_type Hook and modify post type registration Create custom post type hook for products inside function.php file add_action( 'init', 'wpyog_register_products_cpt' ); /**  * Register Products Custom Post Type   */ function wpyog_register_products_cpt() {     // change 'wpyog_products' to whatever your text_domain is.          /** Setup labels */     $labels = array(         'name'               => x_( 'Products', 'wpyog_products' ),         'singular_name'      => x_( 'Product', 'wpyog_products' ),         'add_new'            => x_( 'Add New', 'wpyog_products' ),         'all_items'          => x_( 'All Products', 'wpyog_products' ),         'add_new_item'  ...

How to Create a jQuery Autocomplete in Wordpress

How to Create a jquery-ui Autocomplete in wordpress. Autocomplete provides suggestions while you type into the text field. In Wordpress we fetch dynamically matched pattern. Include javascript and css files in header. Create action inside functions.php or inside plugin code. add_action('wp_head', 'custom_register_scripts'); function custom_register_scripts(){ wp_register_style( 'techsudhir_jquery_ui_css', plugin_dir_url(__FILE__) . 'css/jquery-ui.css', false,'1.0.0' ); wp_enqueue_style( 'techsudhir_jquery_ui_css' ); wp_register_script('techsudhir_jquery_ui_js',plugin_dir_url(__FILE__) . 'js/jquery-ui.js',array('jquery'),'1.1', false); wp_enqueue_script('techsudhir_jquery_ui_js'); wp_localize_script( 'techsudhir_autocomplete', 'jqueryAutocomplete', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( 'techsudhir_...

How to use Ajax in WORDPRESS

How AJAX Works In WordPress What's AJAX? AJAX stands for Asynchronous JavaScript And XML . It is the use of the XMLHttpRequest object to communicate with servers, which means it can communicate with the server, exchange data, and update the page without having to refresh the page. Step1: Define the Ajax URL. var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' );?>'; Step2: Define its action and perform with using POST method var emailAddress = jQuery('#uemail').val(); var searchData = { action: 'get_registered_email', email_address:emailAddress, } Step 3: Perform ajax request jQuery.ajax({ url: ajaxurl, type: "POST", data: searchData, success: function(data){   jQuery("div#divLoading").removeClass('show');   jQuery('#memberResult').html(data);   //alert(data); }, error: function(errorThrown){ alert(errorThrown); } }); Step 4: Use Wordpress 2 ajax hooks...

6 guaranteed steps how to create CRON JOB FUNTION in wordpress

Create Cron Job function in Wordpress plugin Step 1: Register function on plugin activate  register_activation_hook(__FILE__, 'activate_one'); Step 2: add_filter function for interval //Filter for Adding multiple intervals add_filter( 'cron_schedules', 'intervals_schedule' ); // define interval function   function intervals_schedule($schedules) {   $schedules['everyminute'] = array(    'interval' => 60, // Every 1 minutes    'display'  => __( 'Every 1 minutes' )   );   return $schedules;  } Step 3: Activate hook function   //Schedule a first action if it's not already scheduled   function activate_one() {   if (!wp_next_scheduled('wpyog_cron_action')) {    wp_schedule_event( time(), 'everyminute', 'wpyog_cron_action');   }  } Step 4: Cron hook function   //Hook into that action that'll fire after 1 minutes   add_action('wpyog_cron_action', 'execute_...