Skip to content

Instantly share code, notes, and snippets.

View danielpataki's full-sized avatar

Daniel Pataki danielpataki

View GitHub Profile
@danielpataki
danielpataki / custom-post-type-features.php
Last active December 2, 2022 08:49
Custom Post Type Example
function my_custom_post_types() {
$args = array(
'label' => 'Recipes',
'hierarchical' => true,
'taxonomies => array( 'post_tag' )
);
register_post_type( 'recipe', $args );
}
add_action( 'init', 'my_custom_post_types' );
<?php
/**
* Template Name: Alphabetical Posts
*/
get_header(); ?>
<div id="main-content" class="main-content">
<?php
@danielpataki
danielpataki / post-list-template-acf-options.php
Last active August 29, 2015 14:07
Custom Post List Template
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_post-list-options',
'title' => 'Post List Options',
'fields' => array (
array (
'key' => 'field_543f8a046d65e',
'label' => 'Authors',
'name' => 'authors',
$args = array(
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>'
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<p class="comment-form-author">' .
'<label for="author">' . __( 'Name', 'domainreference' ) . '</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' /></p>',
@danielpataki
danielpataki / enqueue-register.php
Last active February 19, 2018 20:45
WordPress Enqueues
function my_assets() {
wp_register_script( 'owl-carousel', get_stylesheet_directory_uri() . '/owl.carousel.js', array( 'jquery' ) );
wp_enqueue_script( 'owl-carousel' );
}
add_action( 'wp_enqueue_scripts', 'my_assets' );
@danielpataki
danielpataki / custom.php
Last active August 29, 2015 14:08
Editor Style Examples
function my_editor_styles() {
add_editor_style( 'admin/editor.css' );
}
add_action( 'after_setup_theme', 'my_editor_styles' );
@danielpataki
danielpataki / action.php
Last active November 27, 2016 01:10
WordPress Emails
function set_mail_html_content_type() {
return 'text/html';
}
add_action( 'publish_post', 'author_publish_notice', 10 ,2 );
function author_publish_notice( $ID, $post ) {
if( 'post' == $post->post_type ) {
return;
}
@danielpataki
danielpataki / commentcount.php
Last active August 29, 2015 14:08
Dahsboard Widgets
global $wpdb;
for( $i=1; $i <= 5; $i++ ) {
$this_week = 7 * $i;
$last_week = 7 * ( $i - 1);
$comment_counts[] =
$wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_date > '" . date('Y-m-d H:i:s', strtotime('-' . $this_week . ' days')) . "' AND comment_date < '" . date('Y-m-d H:i:s', strtotime('-' . $last_week . ' days')) . "'" ) ;
@danielpataki
danielpataki / basic-shortcode.php
Last active August 29, 2015 14:08
Grid Shortcode
function my_code_output( $atts, $content ) {
return '<pre><code>' . $content . '</code></pre>';
}
add_shortcode('code', 'my_code_output');
@danielpataki
danielpataki / admin-targeting-hook.php
Last active August 29, 2015 14:08
Common WordPress Code Mistakes
function user_edit_script( $hook ) {
if ( 'profile.php' != $hook ) {
return;
}
wp_enqueue_script( 'my-user-edit', plugin_dir_url( __FILE__ ) . 'js/my-user-edit.js' );
}
add_action( 'admin_enqueue_scripts', 'user_edit_script' );