Skip to content

Instantly share code, notes, and snippets.

@ahmedch1
ahmedch1 / ap.js
Created June 15, 2024 06:29
Call js function in app js (Sage wordpress)
import domReady from '@roots/sage/client/dom-ready';
+import {custom} from "@scripts/custom.js";
/**
* Application entrypoint
*/
domReady(async () => {
// application code
-
+ //custom();
<?php
/*
Plugin Name: Posts FE
Description: Posts FE
Version: 1.0
*/
// Enregistrement du shortcode pour le formulaire
add_shortcode('mon_formulaire', 'mon_formulaire_shortcode');
In Style style.css add
Text Domain: ahmedsite
ahmedsite : the name of the theme
In functions.php
add_action('init', function() {
pll_register_string('ahmedsite', 'We are Testing Here');
@ahmedch1
ahmedch1 / Load Webp Version if exists
Created September 4, 2022 18:17
Load Webp Version if exists
<?php
// directory
$directory=__DIR__ . '\gif';
function replace_extension($filename, $extension) {
if (($pos = strrpos($filename , '.')) !== false) {
$filename = substr($filename, 0, $pos);
}
return $filename . '.' . $extension;
add_action('wp_enqueue_scripts', 'customize_cf7_dequeue');
function customize_cf7_enqueue($content)
{
if (has_shortcode($content, 'contact-form-7') && function_exists('wpcf7_enqueue_styles')) {
$content = '<link href="' . esc_url(wpcf7_plugin_url('includes/css/styles.css') . '?ver=' . WPCF7_VERSION) . '" rel="stylesheet" type="text/css">' .
$content;
wpcf7_enqueue_scripts();
}
return $content;
/**
* Callback function that returns true if the current page is a WooCommerce page or false if otherwise.
*
* @return boolean true for WC pages and false for non WC pages
*/
function is_wc_page() {
return class_exists( 'WooCommerce' ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() );
}
add_action( 'template_redirect', 'conditionally_remove_wc_assets' );
if ( !is_user_logged_in() ) {
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
## VARVY_SCRIPT
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
* Use Defer in javascript (Load Js scripts in order)
* Load Js in the Footer
* Use Tiny Png for optimizing images (useful in static and quasi static websites)
* Use CloudFlare
* Use LiteSpeedCache Server
* Use Litespeed Cache Plugin (Wordpress)
* Tools to Test Speed
<?php
// Add FieldName MetaBox
abstract class FieldName_Meta_Box {
/**
* Set up and add the meta box.
*/
public static function add() {
$screens = [ 'posttypename' ];