wp snippets
enqueue styles in the footer, used for critical css
function my_deregister_styles() { wp_deregister_style(‘parent’); wp_deregister_style( ‘divi-style’ ); wp_deregister_style( ‘tt-widget-css’ ); } add_action(‘wp_enqueue_scripts’, ‘my_deregister_styles’, 100);
//load style on footer function pxs_add_footer_styles() { $parent_style = ‘parent-style’; wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ ); wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/style.css’, array(‘parent-style’) );
1
wp_enqueue_style( 'tt-widget-css', get_stylesheet_directory_uri() . '/wp-content/plugins/ticket-tailor/tt-widget.css' );
}; add_action( ‘get_footer’, ‘pxs_add_footer_styles’ );
// Move Yoast to bottom function yoasttobottom() { return ‘low’; }
add_filter( ‘wpseo_metabox_prio’, ‘yoasttobottom’);
//redirect user on failed login add_action( ‘wp_login_failed’, ‘my_callback’ ); function my_callback() { if (! is_user_logged_in()) { wp_redirect( ‘https://example.com.au’, 301 ); exit(); } else { wp_redirect( ‘https://example.com.au/login/’, 301 ); exit(); } }
//style header info /* Theme Name: Twenty Seventeen Theme URI: https://wordpress.org/themes/twentyseventeen/ Author: the WordPress team Author URI: https://wordpress.org/ Description: Twenty Seventeen brings your site to life with immersive featured images and subtle animations. With a focus on business sites, it features multiple sections on the front page as well as widgets, navigation and social menus, a logo, and more. Personalize its asymmetrical grid with a custom color scheme and showcase your multimedia content with post formats. Our default theme for 2017 works great in many languages, for any abilities, and on any device. Version: 1.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: twentyseventeen Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready This theme, like WordPress, is licensed under the GPL. Use it to make something cool, have fun, and share what you’ve learned with others. */
//wp_schedule_event https://wordpress.stackexchange.com/questions/179694/wp-schedule-event-every-day-at-specific-time
//secure area <?php /* include via page template Pipe all knowledge base users through the one page template to easily test if user is logged in or not. */ ?>
//date counter <?php
function DateCounter($atts){
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$startDate = $atts["startdate"];
$endDate = strtolower($atts["enddate"]);
switch (strtolower($atts["format"])) {
case "year":
case "years":
$startDate = new DateTime($startDate);
$endDate = new DateTime($endDate);
$difference = $endDate->diff($startDate);
$result = $difference->y;
break;
case "month":
case "months":
$startDate = strtotime($startDate);
$endDate = strtotime($endDate);
$min_date = min($startDate, $endDate);
$max_date = max($startDate, $endDate);
$i = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
$i++;
}
$result = $i;
break;
case "day":
case "days":
$startDate = strtotime($startDate);
$endDate = strtotime($endDate);
$difference = $endDate - $startDate;
$result = floor($difference / (60*60*24));
break;
case "currentyear":
$result = date("Y");
break;
case "currentmonth":
$result = date("m");
break;
case "currentday":
$result = date("d");
break;
}
return $result; }
add_shortcode( ‘DateCounter’, ‘DateCounter’ );
?>
//featured image <?php if ( has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), $pxs_img_size ); echo ‘’; ?> <?php }
Comments powered by Disqus.