
<?php $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc"); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, $pages); $prevID = $pages[$current-1]; $nextID = $pages[$current+1]; if (!empty($prevID) || !empty($nextID)) { ?> <div class="navigation-wrapper"> <div class="navigation"> <?php if (!empty($prevID)) { ?> <div class="cell cell-previous"> <a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>"> Précédent<br> <strong><?php echo get_the_title($prevID); ?></strong> </a> </div> <?php } ?> <?php if (!empty($nextID)) { ?> <div class="cell cell-next"> <a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>"> Suivant<br> <strong><?php echo get_the_title($nextID); ?></strong> </a> </div> <?php } ?> </div> </div>
// define the woocommerce_created_customer callback function action_woocommerce_created_customer( $customer_id, $new_customer_data, $password_generated ) { // make action magic happen here... }; // add the action add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 );
// functions.php function custom_button_shortcode( $atts, $content = null ) { extract( shortcode_atts( array( 'url' => '', 'title' => '', 'target' => '', 'text' => '', ), $atts ) ); $content = $text ? $text : $content; if ( $url ) { $link_attr = array( 'href' => esc_url( $url ), 'title' => esc_attr( $title ), 'target' => ( 'blank' == $target ) ? '_blank' : '', 'class' => 'custombutton' ); $link_attrs_str = ''; foreach ( $link_attr as $key => $val ) { if ( $val ) { $link_attrs_str .= ' ' . $key . '="' . $val . '"'; } } return '<a' . $link_attrs_str . '>' . do_shortcode( $content ) . '</a>'; } else { return '<span class="custombutton"><span>' . do_shortcode( $content ) . '</span></span>'; } } add_shortcode( 'custombutton', 'custom_button_shortcode' ); function register_button( $buttons ) { array_push( $buttons, "|", "custombutton" ); return $buttons; } function add_plugin_custom_button( $plugin_array ) { $plugin_array['custombutton'] = get_template_directory_uri() . '/js/custombutton.js'; return $plugin_array; } function my_custom_button_shortcode() { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) { return; } if ( get_user_option('rich_editing') == 'true' ) { add_filter( 'mce_external_plugins', 'add_plugin_custom_button' ); add_filter( 'mce_buttons', 'register_button' ); } } add_action('init', 'my_custom_button_shortcode');
// custombutton.js (function() { tinymce.create('tinymce.plugins.custombutton', { init : function(ed, url) { ed.addButton('custombutton', { title : 'Custom Button', image : url+'/custombutton.svg', onclick : function() { var href = prompt("Href", "https://go.merlinleonard.com/"); var title = prompt("Title", "Call to Action"); var target = prompt("Target", "_blank"); ed.execCommand('mceInsertContent', false, '[custombutton url="'+href+'" target="'+target+'" text="'+title+'"]'); } }); }, createControl : function(n, cm) { return null; }, getInfo : function() { return { longname : "Custom Button", author : 'Otowui.com', authorurl : 'https://www.otowui.com', version : "1.0" }; } }); tinymce.PluginManager.add('custombutton', tinymce.plugins.custombutton); })();
// custombutton.svg <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M384 32H64C28.65 32 0 60.65 0 96v320c0 35.34 28.65 64 64 64h320c35.35 0 64-28.66 64-64V96C448 60.65 419.3 32 384 32zM330.5 323.9c0 6.473-3.889 12.3-9.877 14.78c-5.979 2.484-12.86 1.105-17.44-3.469l-45.25-45.25l-67.92 67.92c-12.5 12.5-32.72 12.46-45.21-.0411l-22.63-22.63C109.7 322.7 109.6 302.5 122.1 289.1l67.92-67.92L144.8 176.8C140.2 172.2 138.8 165.3 141.3 159.4c2.477-5.984 8.309-9.875 14.78-9.875h158.4c8.835 0 15.1 7.163 15.1 15.1V323.9z"/></svg>
//functions.php function customimage_shortcode( $atts, $content = null ) { extract( shortcode_atts( array( 'url' => '', 'text' => '', ), $atts ) ); $imgurl = $url ? $url : $imgurl; $content = $text ? $text : $content; if ( $url ) { foreach ( $link_attr as $key => $val ) { if ( $val ) { $link_attrs_str .= ' ' . $key . '="' . $val . '"'; } } return '<figure class="customimage"><img src="' . $imgurl . '"/><figcaption>' . do_shortcode( $content ) . '</figcaption></figure>'; } } add_shortcode( 'customimage', 'customimage_shortcode' ); function register_customimage( $buttons ) { array_push( $buttons, "", "customimage" ); return $buttons; } function add_plugin_customimage( $plugin_array ) { $plugin_array['customimage'] = get_template_directory_uri() . '/js/customimage.js'; return $plugin_array; } function my_customimage_shortcode() { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) { return; } if ( get_user_option('rich_editing') == 'true' ) { add_filter( 'mce_external_plugins', 'add_plugin_customimage' ); add_filter( 'mce_buttons', 'register_customimage' ); } } add_action('init', 'my_customimage_shortcode');
// customimage.js (function() { tinymce.create('tinymce.plugins.customimage', { init : function(ed, url) { ed.addButton('customimage', { title : 'Custom Image', image : url+'/customimage.svg', onclick : function() { var title = prompt("Text", "Call to Action"); var target = prompt("Target", "_blank"); ed.execCommand('mceInsertContent', false, '[customimage url="'+href+'" text="'+title+'"]'); } }); }, createControl : function(n, cm) { return null; }, getInfo : function() { return { longname : "Custom Image", author : 'Otowui.com', authorurl : 'https://www.otowui.com', version : "1.0" }; } }); tinymce.PluginManager.add('customimage', tinymce.plugins.customimage); })();
// customimage.svg <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 448 512" style="enable-background:new 0 0 448 512;" xml:space="preserve"><path d="M146.7,228.1l-46.7,64c-3.5,4.9-4.1,11.3-1.3,16.7c2.8,5.3,7.4,8.7,14.3,8.7h224c5.9,0,11.3-3.2,14.1-8.4 c2.8-5.2,2.5-11.5-0.8-16.4l-85.3-128c-3-4.4-8-7.1-13.3-7.1s-10.4,2.7-13.3,7.1l-53.6,80.3l-12.2-16.8c-3-4.2-7.8-6.6-12.9-6.6 S149.8,223.9,146.7,228.1z M401,29.5H49c-26.4,0-48,21.6-48,48v352c0,26.4,21.6,48,48,48h352c26.4,0,48-21.6,48-48v-352 C449,51.1,427.4,29.5,401,29.5z M385,349.5H65v-256h320V349.5z M129,189.5c17.6,0,32-14.4,32-32s-14.4-32-32-32s-32,14.4-32,32 S111.4,189.5,129,189.5z"/></svg>
// unregister all widgets function unregister_default_widgets() { unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); unregister_widget('WP_Widget_Search'); unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Recent_Posts'); unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_RSS'); unregister_widget('WP_Widget_Tag_Cloud'); unregister_widget('WP_Nav_Menu_Widget'); unregister_widget('Twenty_Eleven_Ephemera_Widget'); unregister_widget('WP_Widget_Media_Audio'); unregister_widget('WP_Widget_Media_Image'); unregister_widget('WP_Widget_Media_Video'); //unregister_widget('WP_Widget_Custom_HTML'); } add_action('widgets_init', 'unregister_default_widgets', 11);
// REORDER MENU add_filter('custom_menu_order', function() { return true; }); add_filter('menu_order', 'my_new_admin_menu_order'); function my_new_admin_menu_order( $menu_order ) { $new_positions = array('index.php' => 1, 'edit.php' => 2, 'upload.php' => 7, 'edit.php?post_type=page' => 3, 'edit-comments.php' => 8); function move_element(&$array, $a, $b) { $out = array_splice($array, $a, 1); array_splice($array, $b, 0, $out); } foreach( $new_positions as $value => $new_index ) { if( $current_index = array_search( $value, $menu_order ) ) { move_element($menu_order, $current_index, $new_index); } } return $menu_order; };
<?php /* Set posts per page for a custom post type in wordpress.php */ ?> <?php function set_posts_per_page_for_towns_cpt( $query ) { if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'towns' ) ) { $query->set( 'posts_per_page', '10' ); } } add_action( 'pre_get_posts', 'set_posts_per_page_for_towns_cpt' ); ?>
// Add Custom post types to tags and categories archives function add_cpts_to_archive_page( $query ) { if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'custom-post-type-1', 'custom-post-type-2' )); } return $query; } add_filter( 'pre_get_posts', 'add_cpts_to_archive_page' );
<?php /* Show thumbnails in WordPress Posts Pagination */ ?> <?php if( $prev_post = get_previous_post() ): ?> <div class="nav-box previous"> <?php $prevthumbnail = get_the_post_thumbnail($prev_post->ID, 'thumbnail' );?> <?php previous_post_link('%link',"$prevthumbnail <p>%title</p>", TRUE); ?> </div> <?php endif; ?> <?php if( $next_post = get_next_post() ): ?> <div class="nav-box next"> <?php $nextthumbnail = get_the_post_thumbnail($next_post->ID, 'thumbnail' ); ?> <?php next_post_link('%link',"$nextthumbnail <p>%title</p>", TRUE); ?> </div> <?php endif; ?>
<?php function synth_copyright() { global $wpdb; $copyright_dates = $wpdb->get_results(" SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status = 'publish' "); $output = ''; if($copyright_dates) { $copyright = "© " . $copyright_dates[0]->firstdate; if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) { $copyright .= '-' . $copyright_dates[0]->lastdate; } $output = $copyright.' - Site réalisé par <a href="https://synth.agency" target="_blank">synth.agency</a>'; } return $output; } ?>
// Remove custom post types from search result add_action('pre_get_posts', 'remove_cpts_from_search_results'); function remove_cpts_from_search_results($query) { if (is_admin() || !$query->is_main_query() || !$query->is_search()) { return $query; } $post_types_to_exclude = array('custom-post-type-1', 'custom-post-type-2'); if ($query->get('post_type')) { $query_post_types = $query->get('post_type'); if (is_string($query_post_types)) { $query_post_types = explode(',', $query_post_types); } } else { $query_post_types = get_post_types(array('exclude_from_search' => false)); } if (sizeof(array_intersect($query_post_types, $post_types_to_exclude))) { $query->set('post_type', array_diff($query_post_types, $post_types_to_exclude)); } return $query; }
<?php // Loop $recent = new WP_Query('post_type=event&post_status=future&order=ASC&orderby=date'); while($recent->;have_posts()) : $recent->the_post(); ?> <div> <a href="<?php the_permalink(); ?>"><?php the_title(); ?> - <?php the_date('l, F j, Y');?></a> </div> <?php endwhile; ?> <?php // Functions.php add_filter('the_posts', 'show_future_posts'); function show_future_posts($posts){ global $wp_query, $wpdb; if(is_single() && $wp_query->post_count ==0){ $posts = $wpdb->get_results($wp_query->request); } return $posts; }; ?>
Loading...
No more items to load