Articles by WP-Snippets

  • Disable JSON Rest API

    The new REST API feature was introduced in WordPress 4.4. This features makes it possible to access your content through an JSON API, which is awesome for external services and clients. This snippet let’s you disable this WordPress REST API, if you for some reason don’t want to use it. Posted in Pure hacks

    READ MORE
  • List All Roles

    This snippet let’s you loop through every role registered in WordPress. If you want to change the capabilities of a role, check out this snippet: Change Role Capabilities. Posted in Pure hacks

    READ MORE
  • Add Body Classes

    This code snippet let’s you add CSS classes to your body tag depending on what page you are on. For this to work you need to change your body tag to look like this: body ?php body_class() ?

    READ MORE
  • Alter Custom Background Behaviour

    By default the custom background is applied on the body. If you want to apply it on another element, you can use this function to customize any background parameter you want, as well as the element on which it’s applied. Code Snippet: // Activate custom background and set callback function if ( function_exists( ‘add_theme_support’ ) […]

    READ MORE
  • Restrict Admin Panel to Administrators Only

    Posted in Admin area, Conditional

    READ MORE
  • Members Only Content Shortcode

    This shotcode allows you to write a private content in a post. For non-members, the login form will appear. Usage: [mem] ..content.. [/mem] Posted in Snippets

    READ MORE
  • Modify Allowed Upload Mime Types

    This snippet let’s you add or remove allowed file types in the WordPress upload popup. Adding font files like .woff are not allowed by default and this fixes that. Posted in Admin area

    READ MORE
  • Automatic Title Tag

    InWordPress 4.1 and up, you can set the title tag automatically by adding this snippet to functions.php. Remember to remove your own title tag from header.php, and add the wp_head() hook. Posted in Pure hacks

    READ MORE
  • Show PHP Errors

    This shows PHP errors for your WordPress theme. It also checks that the user i an admin and error will only be displayed if it’s true. Posted in Pure hacks

    READ MORE
  • Modify allowed upload mime types

    Share this snippet If you like this snippet, share it with friends!

    READ MORE
  • Plugin: Open Graph Tags for Facebook

    With Open Graph Tags you can define and optimize what the Facebook crawler should pick up and show when people share your content. WP-OG is a plugin that let’s you create and edit these tags in simple way. Optimize each post/page/custom post type, or let WP-OG do everything for you automagically. Download here

    READ MORE
  • Open Graph Tags for Facebook

    Open Graph Tags for Facebook A freebie by Filip Stefansson. Take control of what the Facebook crawler picks up from each page by using Open Graph meta tags. With Open Graph Tags you can define and optimize what the Facebook crawler should pick up and show when people share your content. WP-OG is a plugin that let’s […]

    READ MORE
  • Members only shortcode

    Members only shortcode ?php function member( $atts, $content = null ) { if ( is_user_logged_in() !is_null( $content ) !is_feed() ) { return $content; return ”; } else { $yonlendir = get_permalink(); $form = wp_login_form(array(‘echo’ = false, ‘redirect’ = $yonlendir )); return $form; } } add_shortcode( ‘mem’, ‘member’ ); ? Instructions: This shotcode allows you to […]

    READ MORE
  • Restrict admin panel to administrators only

    Restrict admin panel to administrators only ?php function restrict_admin_access(){ global $current_user; get_currentuserinfo(); if (!array_key_exists(‘administrator’, $current_user-caps)) { wp_redirect( get_bloginfo(‘url’) ); exit; } } add_action(‘admin_init’, ‘restrict_admin_access’, 1); ? Instructions: Enter into functions.php, and all users who are not administrators and try to access the admin panel will be redirected to the homepage URL. Good way of keeping […]

    READ MORE
  • Protect wp-config.php with .htaccess

    Share this snippet If you like this snippet, share it with friends!

    READ MORE
  • Alter custom background behavior

    Alter custom background behavior ?php // Activate custom background and set callback function if ( function_exists( ‘add_theme_support’ ) ) { $defaults = array( ‘default-color’ = ‘000000’, ‘default-image’ = get_template_directory_uri() . ‘/img/background.png’, ‘wp-head-callback’ = ‘my_theme_background_cb’, ‘admin-head-callback’ = ”, ‘admin-preview-callback’ = ” ); add_theme_support( ‘custom-background’, $defaults ); } // Callback function to alter custom background behavior function […]

    READ MORE
  • Giveaway: Three Premium ThemeFuse Themes for WordPress

    The good people of ThemeFuse are about to giveaway 3 WordPress themes licenses, and we can tell you just how to enter for a chance to win. If you are selected, you will get to download one complete WordPress theme from ThemeFuse’s large library of top quality templates. This means that your WordPress blog or […]

    READ MORE
  • WordPress Tutorial: Truncate Post Title

    <?php  function customTitle($limit) { $title = get_the_title($post-ID); if(strlen($title) $limit) { $title = substr($title, 0, $limit) . ‘…’; } echo $title; }  ?> Instructions: This is just a fix on Josh McDonald’s snippet to remove the ‘…’ if the title is smaller than the $limit. Paste this function in your functions.php file, and whenever you’re in need […]

    READ MORE
  • Scroll Up – WordPress Scroll Plugin

    WordPress Plugin’s make all of our lives easier whether developing websites for client’s or ourselves. They are also perfect for designers, as it means that they can develop amazing websites without having to know the in’s and out’s of PHP and Javascript. Scroll Up is an awesome WordPress Plugin from Filip Stefansson which adds a […]

    READ MORE
  • 15 Premium Responsive Templates To Use As Inspiration

    We’ve collected a list of over 15 great looking responsive WordPress themes for you to use as inspiration when you’re creating your own awesome website! WowWay – $45 WowWay is an incredibly unique and highly interactive WordPress theme for creative portfolios. Based on a responsive grid, packed up with lots of cool features and built […]

    READ MORE