Powered By Blogger

Friday, July 29, 2022

Add wysiwyg editor in WordPress meta box for custom post type or Posts

 add_action( 'add_meta_boxes', function() { 

    add_meta_box('html_myid_61_section', 'TITLEEEEE', 'my_output_function');
});

function my_output_function( $post ) {
    $text= get_post_meta($post, 'SMTH_METANAME' , true );
    wp_editor( htmlspecialchars_decode($text), 'mettaabox_ID', $settings = array('textarea_name'=>'MyInputNAME') );
} add_action( 'save_post', function($post_id) { if (!empty($_POST['MyInputNAME'])) { $datta=htmlspecialchars($_POST['MyInputNAME']);
update_post_meta($post_id, 'SMTH_METANAME', $datta ); } });

Tuesday, December 1, 2020

301 Redirect to replace all spaces to hyphens using htaccess

htaccess clean urls & replacing whitespaces and %20 with -



RewriteCond %{HTTP_HOST} ^\.dev\.site\.com$ [NC]

RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R]

RewriteRule ^Content/Publications/(.*)\.php$ https://dev.site.com/divi/publications/$1 [R=301,L]


REF : https://stackoverflow.com/questions/18935257/htaccess-clean-urls-replacing-whitespaces-and-20-with

https://stackoverflow.com/questions/5821120/301-redirect-to-replace-all-spaces-to-hyphens


Friday, November 13, 2020

update customizer value using php in wordpress

 set_theme_mod('labor_stats_title_8', $value);


https://developer.wordpress.org/reference/functions/set_theme_mod/

Thursday, August 20, 2020

run odometer.js only when user reach the place

 REF : https://github.com/HubSpot/odometer/issues/150

$(document).ready(function(){

$.fn.isInViewport = function() {
  var elementTop = $(this).offset().top;
  var elementBottom = elementTop + $(this).outerHeight();

  var viewportTop = $(window).scrollTop();
  var viewportBottom = viewportTop + $(window).height();

  return elementBottom > viewportTop && elementTop < viewportBottom;
};

$(window).on('resize scroll', function() {
  $('.odometer').each(function() {
    if ($(this).isInViewport()) {
        
      setTimeout(function(){
        $('.odometer').html(240000);
      }, 0);
    } else {
    }
  });
});

});

Monday, May 11, 2020

How to change your search query parameter from ‘s’ to something else

<?php


add_filter('init', function(){

global $wp;


$wp->add_query_var( 'search_query' );

$wp->remove_query_var( 's' );

} );



add_filter( 'request', function( $request ){

if ( isset( $_REQUEST['search_query'] ) ){

$request['s'] = $_REQUEST['search_query'];

}


return $request;

} );

Thursday, February 27, 2020

How to find user assigned how many site in multisite wordpress


  1. select * from wp_blogs
From the output of the command note down the blog_id you want the users of. For eg: say you are wanting the users of the site with blog_id = 2 , next run the following query.
  1. select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities"

REF : https://stackoverflow.com/questions/27495552/how-to-get-users-who-belong-to-a-wordpress-multisite-blog-site-with-sql