Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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';
}