{"generator":"Code Snippets v3.6.5.1","date_created":"2024-09-06 20:49","snippets":[{"id":5,"name":"Facebook - M\u00e9tadonn\u00e9es Open Graph","desc":"<p>G\u00e9n\u00e8re des m\u00e9tadonn\u00e9es Open Graph g\u00e9n\u00e9riques pour les pages (image nomm\u00e9e \u00ab fb-share \u00bb) et des sp\u00e9cifiques pour les articles (\u00ab image mise de l'avant \u00bb).<\/p>","code":"\/* v.2024-09-06 *\/\n\nfunction msw_metadonnees_facebook() {\n\tglobal $post;\n\t\n\t\/\/ Si ce n'est ni article, ni une page\n    if ( !is_singular() ) {\n        return;\n\t}\n\n\t\/\/ Title\n\t$meta_title = get_post_meta( $post->ID, 'wpmsw-meta-title', true );\n\tif ( empty($meta_title) ) {\n\t\t$meta_title = get_the_title();\n\t}\n\techo '<meta property=\"og:title\" content=\"' , $meta_title , '\">' , PHP_EOL;\n\t\n\t\/\/ Description\n\t$meta_description = get_post_meta( $post->ID, 'wpmsw-meta-desc', true );\n\tif ( !empty($meta_description) ) {\n\t\techo '<meta property=\"og:description\" content=\"' , $meta_description , '\">' , PHP_EOL;\n\t}\n\t\n\t\/\/ Url\n    echo '<meta property=\"og:url\" content=\"' . get_permalink() . '\">', PHP_EOL;\n\t\n\t\/\/ Type\n\tif ( is_singular('post') ) {\n\t\techo '<meta property=\"og:type\" content=\"article\">', PHP_EOL;\n\t} else {\n\t\techo '<meta property=\"og:type\" content=\"website\">', PHP_EOL;\n\t}\n\t\n\t\/\/ Site\n\techo '<meta property=\"og:site_name\" content=\"' , get_bloginfo('name') , '\">' , PHP_EOL;\n\t\n\t\/\/ Image\n\t$image = null;\n\t\n\t\/\/ -- Par d\u00e9faut\n\tif ( !has_post_thumbnail( $post->ID ) ) {\n\t\t$query = get_posts(['post_type' => 'attachment',\n\t\t\t\t\t\t\t'post_status' => 'inherit',\n\t\t\t\t\t\t\t'posts_per_page' => 1,\n\t\t\t\t\t\t\t'title' => 'fb-share'\n\t\t\t\t\t\t   ]);\n\t\tif ($query) {\n\t\t\t$image_post = array_pop($query);\n\t\t\t$image_meta = wp_get_attachment_metadata($image_post->ID);\n\t\t\t$image['src'] = wp_get_attachment_url($image_post->ID);\n\t\t\t$image['width'] = $image_meta['width'];\n\t\t\t$image['height'] = $image_meta['height'];\n\t\t}\n\t\t\n\t\/\/ -- Sp\u00e9cifique aux articles\n\t} else {\n\t\t$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );\n\t\t$image['src'] = esc_attr( $thumbnail_src[0] );\n\t\t$image['width'] = $thumbnail_src[1];\n\t\t$image['height'] = $thumbnail_src[2];\n\t}\n\n\tif ( is_array($image) ) {\n\t\techo '<meta property=\"og:image\" content=\"',$image['src'],'\">',PHP_EOL,\n\t\t\t '<meta property=\"og:image:width\" content=\"',$image['width'],'\">',PHP_EOL,\n\t\t\t '<meta property=\"og:image:height\" content=\"',$image['height'],'\">',PHP_EOL;\n\t}\n}\nadd_action('wp_head', 'msw_metadonnees_facebook', 5);","scope":"front-end","active":true,"modified":"2024-09-06 20:48:15","revision":"31"},{"id":6,"name":"Formulaire - Formater le num\u00e9ro de t\u00e9l\u00e9phone","code":"add_filter( 'wpcf7_mail_tag_replaced',\n\n  function( $replaced, $submitted, $html, $mail_tag ) {\n    if ( 'your-phone' == $mail_tag->field_name() || 'tel-436' == $mail_tag->field_name() ) {\n       $masque_tel \t\t\t= '\/^\\(?([0-9]{3})\\)?( |-|\\.)?([0-9]{3})( |-|\\.)?([0-9]{4})$\/i';\n\t   $masque_telsansfrais \t= '\/^1( |-|\\.)?\\(?([0-9]{3})\\)?( |-|\\.)?([0-9]{3})( |-|\\.)?([0-9]{4})$\/i';\n\t   $replace_tel \t\t \t= '$1 $3-$5';\n\t   $replace_telsansfrais \t= '1 $2 $4-$6';\n\t   if ( preg_match($masque_tel, $submitted) ) {\n\t      $replaced = preg_replace($masque_tel, $replace_tel, $submitted);\n       } elseif ( preg_match($masque_telsansfrais, $submitted) ) {\n\t\t  $replaced = preg_replace($masque_telsansfrais, $replace_telsansfrais, $submitted);\n\t   }\n    }\n    return $replaced;\n  },\n  10, 4\n);","scope":"front-end","active":true,"modified":"2024-09-06 20:48:57","revision":"2"},{"id":7,"name":"Rediriger les pages Auteur vers la page d\u2019accueil","code":"add_action( 'template_redirect', function() {\n    if ( is_author() ) {\n        wp_redirect( home_url(), 301);\n        exit;\n    }\n} );","scope":"front-end","active":true,"modified":"2024-09-06 20:49:10","revision":"2"}]}