Skip to content

Instantly share code, notes, and snippets.

@sudipto-me
sudipto-me / get_Fitst_img.php
Created January 14, 2020 08:10
Get The first image of a post where there is no featured img
function get_first_image($post_id)
{
$first_img = '';
$content_post = get_post($post_id);
$content = $content_post->post_content;
$output = preg_match_all('/<img.+?src=[\'"]([^\'"]+)[\'"].*?>/i', $content, $matches);
$first_img = $matches[1][0];
if ($first_img == '') {
$first_img = get_template_directory_uri() . '/assets/img/placeholder.jpg';
}
@sudipto-me
sudipto-me / disable_right_click.php
Created October 11, 2019 09:16
Disable Right Click for the word press site. Add this code snippet in your theme's functions.php file.
function disable_right_click_callback()
{
?>
<script>
jQuery(document).ready(function() {
jQuery(document).bind("contextmenu", function(e) {
return false;
});
});
</script>
@sudipto-me
sudipto-me / Extract_vc.php
Created May 24, 2019 09:18
Extract some features for the vc map. This are mainly used for the elements: "vc_link","font-size","google_fonts".
/*
* VC Map Extract String
*/
if ( ! function_exists( 'fts_vc_map_extract_string' ) )
{
function fts_vc_map_extract_string( $input )
{
$font_elements = explode('|',$input);
$final_array = array();
foreach ($font_elements as $font_element) {
@sudipto-me
sudipto-me / Shortcode_visual_composer.php
Created May 24, 2019 09:16
Shortcode for the visual composer element.
/*
* Shortcode for the visual composer element.
*/
/**
* Single post two element shortcode
*
* @param Attributes $atts.
* @return string
* @since 1.0.0
*/
@sudipto-me
sudipto-me / VC_MAP.php
Created May 24, 2019 09:14
Visual Composer Custom Element Settings. This settings will show when the element is used in the backend.
/*
* Wp Bakery Page Builder custom Element Code
*/
/*
* vc element single post 2
*/
function fts_single_post_two_vc_callback(){
vc_map( array(
'name' => __('Single Post 2','js_composer'),
'description' => __('Single post section', 'js_composer'),
@sudipto-me
sudipto-me / Img_count.php
Created May 24, 2019 09:08
Get total attachment image count of a wordpress site media from functions file.
/*
*Add this code to your theme's function file or site-specific plugins
*/
function img_count(){
$query_img_args = array(
'post_type' => 'attachment',
'post_mime_type' =>array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
@sudipto-me
sudipto-me / deferjavascript.php
Created March 25, 2019 08:14
To defer javascript files in the website page speed.
/*Defer Parsing of javascript*/
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' defer ";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
@sudipto-me
sudipto-me / popupclose.js
Created March 16, 2019 20:05
Pop up Close
$('body').on('click', '#myModal', function (e) {
if ($(e.target).attr('class') == 'practice_modal active') {
console.log('Class found');
$('#myModal').toggleClass('active');
} else {
console.log('Class not found');
}
console.log($(e.target).attr('class'));
});
/*
* At first retreive the sidebar list and return it in a array
*/
add_action('admin_init','treeservice_select_sidebar');
function treeservice_select_sidebar() {
$sidebar_list = array();
foreach($GLOBALS['wp_registered_sidebars'] as $sidebar) {
$sidebar_list[$sidebar['id']] = $sidebar['id'];
}
return $sidebar_list;
/* -----------------------------------------------------------------------------
* REST API SETUP
* -------------------------------------------------------------------------- */
add_action( 'rest_api_init', function () {
register_rest_route( 'users', '/auth/', array(
'methods' => 'POST',
'callback' => 'meditation_user_auth'
) );
} );