Skip to content

Instantly share code, notes, and snippets.

View jayseventwo's full-sized avatar

jayseventwo jayseventwo

View GitHub Profile
@jayseventwo
jayseventwo / Ajaxify your WordPress comments
Last active July 5, 2021 16:43
Ajaxify your WordPress comments - no more submitting to a new page.
/* ------------------------------------------------------------------ajax comments - add to functions.php ------- */
add_action('comment_post', 'ajaxify_comments',20, 2);
function ajaxify_comments($comment_ID, $comment_status){
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
switch($comment_status){
case "0":
wp_notify_moderator($comment_ID);
case "1": //Approved comment
echo "success";
@jayseventwo
jayseventwo / Woocommerce replace product listing button to link to product
Created November 8, 2017 03:51
Woocommerce replace product listing button to link to product
@jayseventwo
jayseventwo / Rename woocommerce tabs
Created November 7, 2017 00:35
Rename woocommerce tabs
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
$tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
return $tabs;
}
@jayseventwo
jayseventwo / Remove heading from description tab woocommerce
Created November 7, 2017 00:34
Remove heading from description tab woocommerce
// remove redundant "description" heading from description tab
add_filter( 'woocommerce_product_description_heading', 'remove_product_description_heading' );
function remove_product_description_heading() {
return '';
}
@jayseventwo
jayseventwo / hide_admin_functions
Created January 9, 2014 22:03
Hide various aspects of your WordPress admin page - add to functions.php
// ------------------------------hide admin menus in sidebar
function remove_menu_items() {
global $menu;
$restricted = array(__('Dashboard'), __('Pages') , __('Posts'), __('Comments'), __('Media'), __('Plugins'), __('Appearance'), __('Settings'), __('Tools'), __('Users'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
unset($menu[key($menu)]);}
@jayseventwo
jayseventwo / hide_deactivation_link.php
Created October 23, 2013 22:03
If you use a custom plugin to store all your theme functions, you dont want a user to deactivate it. Add this to functions.php or your custom theme plugin to hide the "deactivate" link for your selected plugin.
@jayseventwo
jayseventwo / hidethemes.php
Created October 23, 2013 21:53
Hide the WordPress theme menu from users other than the initial developer (user id is 1). Add to functions.php.
// hide themes menu in WordPress admin for users other than developer
add_action( 'admin_init', 'slt_lock_theme' );
function slt_lock_theme() {
global $submenu, $userdata;
get_currentuserinfo();
if ( $userdata->ID != 1 ) {
unset( $submenu['themes.php'][5] );
unset( $submenu['themes.php'][15] );
}
}
@jayseventwo
jayseventwo / svg_upload.php
Created October 13, 2013 23:20
Enable .svg format uploads in wordPress. Add to functions.php
// enable svg format file upload
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {
// add the file extension to the array
$existing_mimes['svg'] = 'mime/type';
@jayseventwo
jayseventwo / redirect.php
Created September 30, 2013 01:32
Redirect main navigation link to subpage. To do this, Add this code to functions.php, create your main navigation page using this template, then add your selected pages as the sub-pages. When you now click on the main nav button it should redirect to your child page (or first subpage if more than one).
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
@jayseventwo
jayseventwo / global_custom_content
Created September 22, 2013 23:12
Add global custom content areas for your WordPress website. Add to functions.php
add_action('admin_menu', 'add_gcf_interface');
function add_gcf_interface() {
add_options_page('Opening hours', 'Opening hours', '8', 'functions', 'editglobalcustomfields');
}
function editglobalcustomfields() {
?>
<div class='wrap'>
<h2>Opening hours</h2>