Skip to content

Instantly share code, notes, and snippets.

View danielpataki's full-sized avatar

Daniel Pataki danielpataki

View GitHub Profile
@danielpataki
danielpataki / assets.php
Last active February 22, 2021 03:56
Featured Content Widget
public function mfc_assets()
{
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('mfc-media-upload', plugin_dir_url(__FILE__) . 'mfc-media-upload.js', array( 'jquery' )) ;
wp_enqueue_style('thickbox');
}
@danielpataki
danielpataki / add-section.php
Last active February 5, 2021 09:32
Customizer Tutorial
$wp_customize->add_section( 'cd_colors' , array(
'title' => 'Colors',
'priority' => 30,
) );
<?php
/**
* Template Name: Alphabetical Posts
*/
get_header(); ?>
<div id="main-content" class="main-content">
<?php
@danielpataki
danielpataki / compatibility.js
Last active October 17, 2020 00:06
jQuery in WordPress
/* Regular jQuery */
$('.hideable').on('click', function() {
$(this).hide();
})
/* Compatibility Mode */
jQuery('.hideable').on('click', function() {
jQuery(this).hide();
})
@danielpataki
danielpataki / custom-loop.php
Last active July 8, 2020 20:36
Retrieve Any Post You Want With WP_Query
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'future'
);
$scheduled = new WP_Query( $args );
if ( $scheduled->have_posts() ) :
?>
<?php while( $scheduled->have_posts() ) : $scheduled->the_post() ?>
@danielpataki
danielpataki / ajax-action.php
Last active June 1, 2020 03:26
Uploading With WordPress
add_action( 'wp_ajax_nopriv_submit_content', 'my_submission_processor' );
add_action( 'wp_ajax_submit_content', 'my_submission_processor' );
function my_submission_processor() {
// Handle the form in here
}
@danielpataki
danielpataki / latestposts-control.php
Last active April 29, 2020 10:16
Custom Theme Customization Controls
$wp_customize->add_control(
new WP_Customize_Latest_Post_Control(
$wp_customize,
'featpost_control',
array(
'label' => __( 'Select A Featured Post', 'mytheme' ),
'section' => 'header_section',
'settings' => 'featured_post',
'post_type' => 'page'
)
@danielpataki
danielpataki / content.php
Last active March 11, 2020 03:45
Basics Of Theme Development
<h2><a href='<?php the_permalink() ?>'><?php the_title() ?></a></h2>
<div class="content">
<?php the_excerpt() ?>
</div>
@danielpataki
danielpataki / alt-cron.php
Last active November 14, 2019 02:22
WordPress Config File
define( 'ALTERNATE_WP_CRON', true );
@danielpataki
danielpataki / cached-posts.php
Last active July 24, 2019 10:57
WordPress REST API
public function get_remote_posts() {
$posts = get_transient( 'remote_posts' );
if( empty( $posts ) ) {
$response = wp_remote_get( 'http://mysite.com/wp-json/wp/v2/posts/' );
if( is_wp_error( $response ) ) {
return array();
}
$posts = json_decode( wp_remote_retrieve_body( $response ) );