Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / gist:aa388261d0ef58938218
Last active August 29, 2015 14:06
Show Only 5 Blog Posts on Home Page
<?php
/***************************************************************
* Function wpmark_alter_homepage_posts_query()
* Alter query on homepage for show just 5 posts
***************************************************************/
function wpmark_alter_homepage_posts_query( $query ) {
/* check this is not the main query, the admin - if so bail early */
if( ! $query->is_main_query() || is_admin() )
return;
@wpmark
wpmark / latest-tweets-follow-button.php
Created October 8, 2014 09:31
Latest Tweets Widget - Add Follow Button
/***************************************************************
* Function seis_tweets_follow_buttons()
* Adds follow buttons using images from theme image folder with
* names based on the twitter handle given in the widget.
***************************************************************/
function seis_tweets_follow_buttons( $items, $screen_name ) {
/* make the screen name lower case */
$screen_name = strtolower( $screen_name );
@wpmark
wpmark / gist:9d5d2395cb01a2de0179
Created October 8, 2014 11:06
Check If WordPress Post is Older than X Days
<?php
/*******************************
* this will work in the loop
*******************************/
/* check if the posts publish date is older than 60 days */
if( strtotime( $post->post_date ) < strtotime('-60 days') ) {
/* post is older than 60 days - do something with it!! */
@wpmark
wpmark / wp-toplevel-admnin-menu.php
Last active December 12, 2019 19:05
Add a WordPress Admin Top Level Menu
<?php
function wpmark_add_toplevel_menu() {
/* add a new menu item */
add_menu_page(
'My Admin Menu', // page title
'My Admin Menu', // menu title
'edit_posts', // capability
'wpmark_admin_menu', // menu slug
'wpmark_admin_menu_content', // callback function
@wpmark
wpmark / wp-admin-page-function.php
Created November 19, 2014 16:09
WordPress Admin Page Content Function
<?php
function wpmark_admin_menu_content() {
?>
<div class="wrap">
<h2>My Admin Page</h2>
<?php
@wpmark
wpmark / wp-add-submenu.php
Created November 19, 2014 16:58
Add WordPress Sub Menu
<?php
function wpmark_add_submenu_item() {
/* add the sub menu under content for posts */
add_submenu_page(
'tools.php', // parent slug
'My Sub Menu', // page_title,
'My Sub Menu', // menu_title,
'manage_options', // capability,
'wpmark_submenu_content' // menu_slug,
@wpmark
wpmark / wp-remove-toplevel-admin-menu.php
Created November 19, 2014 17:08
WordPress Remove Top Level Admin Menu
<?php
function wpmark_remove_posts_menu_item() {
/* remove the sub menu item */
remove_menu_page(
'edit.php', // parent slug
);
}
@wpmark
wpmark / wp-add-posts-as-submenu.php
Created November 19, 2014 17:13
WordPress Add Posts Menu as a Sub Menu
<?php
function wpmark_add_posts_as_submenu() {
/* add the sub menu under content for posts */
add_submenu_page(
'wpmark_admin_menu', // parent slug
'Posts', // page_title,
'Posts', // menu_title,
'edit_posts', // capability,
'edit.php' // menu_slug,
@wpmark
wpmark / wp-admin-menu-hierarchy-correction.php
Created November 19, 2014 17:19
WordPress Admin Menu Hierarchy Correction
<?php
function wpmark_menu_hierarchy_correction( $parent_file ) {
global $current_screen;
/* get the base of the current screen */
$screenbase = $current_screen->base;
/* if this is the edit.php base */
if( $screenbase == 'edit' ) {
@wpmark
wpmark / gist:8d96847316d5f46a6174
Created December 1, 2014 18:36
Add Additional Fields to WP Post Type Meta
<?php
function wpptm_add_select_input( $settings ) {
/* add our setting to the settings array */
$settings[] = array(
'type'=> 'select',
'label'=> 'A Select Box',
'id'=> ‘selectbox’,
'options' = array(
array(