Skip to content

Instantly share code, notes, and snippets.

@Sstobo
Sstobo / gist:288ac5b82e27e1e3da5eb291ce52a7c4
Created November 10, 2017 17:59
[WP remove menus from build version] #build #wp #menu
What if we wanted to remove the Editor links from the Appearance/Plugins sub-menus so no internal end user can mess with code from inside WP?
// Remove "Editor" links from sub-menus
function inhabitent_remove_submenus() {
remove_submenu_page( 'themes.php', 'theme-editor.php' );
remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
}
add_action( 'admin_menu', 'inhabitent_remove_submenus', 110 );
The priority number is an optional integer value on a scale of 1 to 999 that determines the priority of order for functions tied to that specific hook.
@Sstobo
Sstobo / gist:2660749890729425f8cc6c8464491e90
Created November 10, 2017 19:58
[WP filters and actions] . #php #wp #hooks #filters #actions
add_setup_theme . -order of initialization]
add_after
after_switch_theme . (action that happens IF a theme gets switched)
body_class
** excerpt_length - change length of custom excerpt (add to loop)
@Sstobo
Sstobo / gist:dd6a6670f0f782973678ea34c446e5a0
Created November 14, 2017 18:56
[Information Architecture] #ia
####### WAYS TO SORT TAXONOMYS ##########
Content audit : go through everything
ROT ANALYSIS: Redundant, out-dated or trivial?
Tree diagrams
Card sorting
######## Wordpress Taxonomies ###########
tags, categories, pages, posts
@Sstobo
Sstobo / gist:fe410434fb3de1b233800367695cab8e
Created November 14, 2017 21:23
[WP Plugin dev] #wp #plugins
function inhabitent_cpt_product() {
$args = array();
register_post_type( 'product', $args );
}
add_action( 'init', 'inhabitent_cpt_product' );
## FLUSH PERMALINK CACHE When adding new content type or templates OR HAVING PROBLEMS ##
go to settings on dash
permalinks ---> save
@Sstobo
Sstobo / gist:e62cd495d72a9191097bfb5aac1b05d0
Created November 14, 2017 21:24
[Template Name in WP] #wp #templates
VERY IMPORTANT
<?php
/**
* Template Name: About Page
*
* @package RED_Starter_Theme
*/
Create page from page.php
Create page in pages
Label Template in PHP file (comments in top)
Create fields, choose page template (links to page.php template label)
Go to page, select template file, get the field
@Sstobo
Sstobo / gist:b69f56d00b6235e5f8b96fc9fc8ff2cb
Last active November 17, 2017 14:27
[extras.php dynamic css generation] #php #fp
function inhab_dynamic_css() {
if ( ! is_page_template( 'about.php')) {
return;
}
$image = CFS()->get('about_header_image') ;
if (! $image) {
return;
@Sstobo
Sstobo / WP Custom post loops.txt
Created November 15, 2017 19:20
[WP Custom post loops] #wp #php #posts #post-loops
Use WP_Query when you need to create a paginated query
Use get_posts() to create static, additional loops (e.g. a list of a few recent posts on a homepage, etc.)
############## DEFAULT LOOP
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2> ###### POST TITLE
<?php the_content(); ?> ###### POST CONTENT
<?php endwhile; ?>
@Sstobo
Sstobo / gist:30d851723be80b95ca4bc0835b6079da
Created November 15, 2017 19:21
[Image path in WP] #wp #images
<img src= "<?php echo get_template_directory_url() . '/images/inhab-logo.svg' ?>"
@Sstobo
Sstobo / gist:1b01e7e7d32e59261b8ab9e5c9ef4fe8
Last active November 17, 2017 14:24
[Archive page and JS] #wp
appearance ###########Adding a new archive page (products)
menus
products (screen options)
view all
archives
add
rename - shop
url - product
(create archive-product.php)
get $terms - taxonomy - product-type