A jquery back button: jQuery(document).ready(function($){ $(‘button.back’).click(function(){ parent.history.back(); return false; }); }); Your html would be: <button class=”back”>Back</button> Plus whatever css you want to use to style the button.
For more code ideas go to my GitHub gists:
https://gist.github.com/johnnya23
Custom Bullet Icons for Lists
I prefer this method because it gives me more control over bullet position. <ul class=”pdf-list”> <li><a href=”http://address.pdf”>Title</a></li> <li><a href=”http://address.pdf”>Title</a></li> <li><a href=”http://address.pdf”>Title</a></li> <li><a href=”http://address.pdf”>Title</a></li> </ul> and the css (adjust padding based on the size of the image): ul.pdf-list li { background: url(‘../images/pdf-icon.png’) no-repeat left center; padding: 3px 0px 3px 30px; list-style: none; } In this case […]
100% Height Sidebar
Say you want the background and/or border of the sidebar to extend the full height of the page… .container { overflow: hidden; …. } #sidebar { margin-bottom: -5000px; padding-bottom: 5000px; …. }
Display List of Related Pages from Hierarchy in Sidebar
Linked pages related to the current page. If is root page shows itself as title with all children below. Else shows immediate parent as title with all pages at its level below (depth can be changed, with -1 showing all without hierarchy). function jma_sidebar_addon() { global $post; if($post->post_parent) { $children = wp_list_pages(‘title_li=&child_of=’.$post->post_parent.’&echo=0&depth=1′); }else{ $children = […]
Get Image ID from Source
Finds the image id given the source. Or returns false. function get_attachment_id_from_src( $attachment_url = ” ) { global $wpdb; $attachment_id = false; // If there is no url, return. if ( ” == $attachment_url ) return $attachment_id; $query = “SELECT ID FROM {$wpdb->posts} WHERE guid=’$attachment_url'”; if($wpdb->get_var($query)){ $attachment_id = $wpdb->get_var($query); }else{ // If this is the […]
Multi-site Menu (experimental)
Starting in 4.7 using REST API – This is JumpStart specific. On “host” site: function get_menu() { # Change ‘menu’ to your own navigation slug. return wp_nav_menu(themeblvd_get_wp_nav_menu_args(‘primary’)); } //https://hosturl.com/wp-json/myroutes/menu add_action(‘rest_api_init’, function () { register_rest_route(‘myroutes’, ‘/menu’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_menu’, )); }); On “receiving” site: function jma_child_header_menu_addon() { $response = wp_remote_get(‘https://hosturl.com/wp-json/myroutes/menu’); /*echo ‘<pre>’; […]
CSS Columns
Need to style code into columns. This is for simple auto-generated paragraph in a post or page. .postid-1121 .entry-content > p { width: 48%; margin-left: 4%; float: left; } .postid-1121 .entry-content > p:nth-of-type(2n+1) { clear: both; margin-left: 0; } or for three col: .postid-1121 .entry-content > p { width: 30%; margin-left: 5%; float: left; } […]
Versatile html Shortcode Wrapper
Sometimes as I code a page I find it necessary to use some specific html to get the job done. the problem is that when I hand the site over to the client and they start editing in the Visual editor there is a danger that they will inadvertently over-write my html (which isn’t visible […]
Display Posts by Category [shortcode]
Suppose we want to display a list of post links in the sidebar that are in “child” categories of the “News” category (ie “Boating News” followed by its posts, “Fishing News” followed by its posts, in this case from the last 90 days because of the filter). We could include this code in functions.php: add_filter(‘widget_text’, […]