Skip to content

Instantly share code, notes, and snippets.

@mattwilding
mattwilding / gist:311099c0be818a589008eacf66ed4328
Created October 31, 2019 10:40
custom post with download link
add_shortcode('sg_whitepaper_list', 'sgWhitepaperListFunction');
function sgWhitepaperListFunction(){
$h = '<article class="whitepapers-list">';
$loop = new WP_Query( array(
'post_type' => 'whitepaper',
'posts_per_page' => -1
)
);
function my_shortcode_function() {
return '<p>This is generated by my shortcode</p>';
}
add_shortcode( 'my_shortcode', 'my_shortcode_function' );
// enter the shortcode [my_shortcode] to your page/post content and the page/post will display "This is generated by my content" in <p> tags
function my_content_shortcode_function( $atts, $content = null ) {
<?php
get_header();
$show_default_title = get_post_meta( get_the_ID(), '_et_pb_show_title', true );
$is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
?>
<?php
/*
Template Name: Restricted Page
*/
get_header();
$is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
@mattwilding
mattwilding / gist:a3599268a0926eddef65
Created March 8, 2016 11:28
google map markers for custom post types
<?php
$args = array(
'post_type' => 'business',
'posts_per_page' => -1,
);
$business_query = new WP_Query($args);
$location_record = array();
$categories = array();
if ( $business_query->have_posts() ) : while ( $business_query->have_posts() ) : $business_query->the_post();
$the_ID = get_the_ID(); //echo '<pre>'.$the_ID.'</pre>';
@mattwilding
mattwilding / gist:030570771dfd4e726447
Created February 17, 2016 22:52
Divi theme - move blog/woocommerce product sidebar to the left
remove_filter( 'body_class', 'et_divi_sidebar_class' );
function override_divi_sidebar_class( $classes ) {
// Set Woo shop and taxonomies layout.
if ( class_exists( 'woocommerce' ) && ( is_woocommerce() && ( is_shop() || is_tax() ) ) ) {
$page_layout = et_get_option( 'divi_shop_page_sidebar', 'et_left_sidebar' );
}
// Set post meta layout which will work for all third party plugins.
elseif ( false == ( $page_layout = get_post_meta( get_queried_object_id(), '_et_pb_page_layout', true ) ) ) {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
@mattwilding
mattwilding / gist:61ee4025905925910b02
Created December 2, 2015 10:43
wordpress redirect login by role
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
$post = array(
'ID' => [ <post id> ] // Are you updating an existing post?
'post_content' => [ <string> ] // The full text of the post.
'post_name' => [ <string> ] // The name (slug) for your post
'post_title' => [ <string> ] // The title of your post.
'post_status' => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ] // Default 'draft'.
'post_type' => [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ] // Default 'post'.
'post_author' => [ <user ID> ] // The user ID number of the author. Default is the current user ID.
'ping_status' => [ 'closed' | 'open' ] // Pingbacks or trackbacks allowed. Default is the option 'default_ping_status'.
'post_parent' => [ <post ID> ] // Sets the parent of the new post, if any. Default 0.