Skip to content

Instantly share code, notes, and snippets.

@ikawka
Last active August 29, 2015 14:11
Show Gist options
  • Save ikawka/72dc29d76dd72d58c67b to your computer and use it in GitHub Desktop.
Save ikawka/72dc29d76dd72d58c67b to your computer and use it in GitHub Desktop.
Wordpress Notes
<?php
//get current URL
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
//add ajax actions in the admin page
add_action( 'wp_ajax_your_action', 'yourCallback' );
function yourCallback(){
//do something here and echo
exit(); //this is important or else wordpress will echo 0 and adds to your output;
}
//in your javascript
$.post(ajaxurl,
{'action': 'add_product', 'add-product': item}, function(d){
//do something with the output
});
//shield you javascript to use jquery $ funtion freely
(function($){
//use regular jquery here...
})(jQuery);
//load wp_editor from ajax
wp_editor( 'content', 'editorid', array('wpautop'=>false, 'textarea_name'=>'fieldname', 'textarea_rows'=>4) );
\_WP_Editors::enqueue_scripts();
print_footer_scripts();
\_WP_Editors::editor_js();
//get permalink by slug
get_permalink( get_page_by_path( 'page-slug-here' ) );
//handle template redirection
function my_page_template_redirect()
{
if( is_page( 'goodies' ) && ! is_user_logged_in() )
{
wp_redirect( home_url( '/signup/' ) );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
//Add Excerpt to Pages
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'my_add_excerpts_to_pages' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment