Skip to content

Instantly share code, notes, and snippets.

antcms

Block or report user

Report or block antcms

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@antcms
antcms / force-style.php
Last active May 11, 2017
Force Wordpress Styles to Update
View force-style.php
//ADD THIS TO YOUR functions.php FILE
//REMOVES VERSION NUMBERS AND REPLACES WITH A RANDOM NUMBER SO STYLE SHEET RELOADS EVERY TIME
function remove_replace_css_ver( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
$newsrc = $src . '?ver=' . rand(111,9999);
return $newsrc;
}
add_filter( 'style_loader_src', 'remove_replace_css_ver', 9999 );
@antcms
antcms / wordpress-remove-quick-edit-categories.php
Created Jul 12, 2016
Remove the Category menu for Authors in the WordPress Quick Edit Menu
View wordpress-remove-quick-edit-categories.php
//REMOVE TAX IN QUICK EDITOR
add_action('admin_head', 'no_tax_display');
function no_tax_display(){
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
echo '<style>
.inline-edit-categories, #acf-form-data {
display: none;
}
</style>';
@antcms
antcms / wordpress-logout-redirect.php
Last active Jul 12, 2016
Logout redirect for front-end users in WordPress, in this case Authors with access to the back end to add posts. Redirects to a front end page called 'Members Home'.
View wordpress-logout-redirect.php
//AUTHOR LOGOUT
add_filter( 'logout_url', 'author_logout_page', 10, 2 );
function author_logout_page( $logout_url, $redirect ) {
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
return home_url( '/members-home/' );
}
}
@antcms
antcms / wp-post-thumbnail-after-paragraph.php
Created Jun 16, 2016
Display the Featured Image after the first paragraph in WordPress
View wp-post-thumbnail-after-paragraph.php
<?php get_header(); ?>
<div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php
$after_p_img = 1;
$content = apply_filters('the_content', $post->post_content);
if(substr_count($content, '<p>') > $after_p_img){
$contents = explode("</p>", $content);
$p_count = 1;
@antcms
antcms / wp-display-cpt-by-term.php
Created Jun 16, 2016
Sort and display WordPress custom post types by taxonomy on Archive or Page
View wp-display-cpt-by-term.php
<?php get_header(); ?>
<h1><?php post_type_archive_title(); ?></h1>
<!-- Set Up Page Anchors -->
<div>
<ul>
<li>Jump to:</li>
<?php
$custom_terms = get_terms('termname'); // Taxonomy
foreach($custom_terms as $custom_term) {
$anchor = $custom_term->slug;
@antcms
antcms / wp-nav-menu-no-div-no-ul.php
Created Jun 16, 2016
Remove DIV and UL from WordPress wp_nav_menu(). This example replaces the registered menu 'header-menu' and replaces 'wp_nav_menu( array( 'theme_location' => 'header-menu' ) ) ;' with the function 'wp_nav_menu_head();' in your theme file. (For functions.php)
View wp-nav-menu-no-div-no-ul.php
<?php
//REMOVE DIV and UL FROM WP_NAV_MENU
function wp_nav_menu_header(){
$options = array(
'echo' => false,
'container' => false,
'theme_location' => 'header-menu',
'fallback_cb'=> 'fall_back_menu'
);
@antcms
antcms / wp-editor-user-access.php
Last active Jun 16, 2016
WordPress Editor can add and delete users, but not Admin level (for functions.php)
View wp-editor-user-access.php
<?php
// ADD USER PERMISIONS FOR EDITOR
function add_theme_caps() {
$role = get_role( 'editor' );
$role->add_cap( 'edit_users' );
$role->add_cap( 'delete_users' );
}
add_action( 'admin_init', 'add_theme_caps');
// EDITOR CAN'T DELETE ADMIN USERS
@antcms
antcms / wp-simple-membership-dynamic-register.php
Last active Sep 30, 2019
Dynamic Registration form for WordPress Simple Membership Plugin (with Form Builder Addon). Choose Membership level from a Select Menu and div below dynamically populates with the correct form for that level. Requires jQuery. https://simple-membership-plugin.com / https://simple-membership-plugin.com/simple-membership-form-builder-addon/
View wp-simple-membership-dynamic-register.php
<div class="registration">
<h2 class="title">Register Here:</h2>
<script type="text/javascript">
$(document).ready(function(){
var hideAll = function() {
$('div[class^=option]').hide();
}
$('#select').on('change', function() {
hideAll();
var category = $(this).val();
@antcms
antcms / wp-page-has-children-conditional.php
Last active Jun 16, 2016
Change the WordPress Template for page.php if it has children
View wp-page-has-children-conditional.php
<?php get_header(); ?>
<?php
if (have_posts()) : while (have_posts()) : the_post();
$pid = get_the_ID();
$args = array(
'post_parent' => $pid,
'post_type' => 'page', // Change as per post type
'numberposts' => -1,
'post_status' => 'publish'
);
@antcms
antcms / wp_auto_page_children.php
Last active Jun 16, 2016
Automatically insert WordPress child pages (and bbPress Forum) when publishing a page / post / custom post type (for functions.php)
View wp_auto_page_children.php
<?php
//AUTO ADD WORDPRESS POST CHILDREN
function add_page_children( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !wp_is_post_revision( $post_id )
&& 'page' == get_post_type( $post_id ) // Change as per required post type
&& 'auto-draft' != get_post_status( $post_id ) ) {
$thispage = get_post( $post_id );
$ptitle = $thispage->post_title; // Set the Parent Page title as a variable to add to new pages
You can’t perform that action at this time.