Skip to content

Instantly share code, notes, and snippets.

Peter Raschendorfer petersplugins

Block or report user

Report or block petersplugins

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
View pp-wp-snippet-use-first-paragraph-as-excerpt.php
// This code snippet uses the first paragraph of an article as excerpt
// use an anonymous function to filter the excerpt
// this changes the behavior of the function the_excerpt() to use the first paragraph
add_filter( 'wp_trim_excerpt', function( $text, $raw_excerpt ) {
$content = apply_filters( 'the_content', get_the_content() );
return substr( $content, 0, strpos( $content, '</p>' ) + 4 );
} ), 10, 2 );
View wp-twenty-sixteen-custom-colums.css
@media screen and (min-width: 56.875em) {
.site-main {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
.site-main h1 {
-moz-column-span: all;
-webkit-column-span: all;
column-span: all;
View pp-wp-snippet-add-mime-types.php
// This code snippet adds additional file types allowed to upload
// Add a custom function to add needed mime types
add_filter( 'upload_mimes', 'add_mime_types' );
function add_mime_types( $mime_types ) {
// add file extensions .svg, .webp, .ai, .eps, .ep, .xml
// more file extensions can be added just the same
View pp-wp-snippet-stop-url-autocorrect.php
// This code snippet disables the URL autocorrection guessing feature of WordPress
// Add a custom function to disable autocorrection guessing
add_filter( 'redirect_canonical', 'stop_url_autocorrect' );
function stop_url_autocorrect( $redirect_url ) {
if ( is_404() && !isset( $_GET['p'] ) ) {
$redirect_url = false;
View pp-wp-snippet-remove-screen-options.php
// This code snippet removes the "Screen Options" Tab from the top right corner of the WordPress Admin
add_filter( 'screen_options_show_screen', '__return_false' );
View pp-wp-snippet-block-admin-access.php
// This code snippet blocks WordPress dashboard access for non admin users
// Add a custom function to check if the user is allowed to access the admin area
add_action( 'init', 'block_admin_access' );
function block_admin_access() {
if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
// Redirect to home page if a non admin user tries to access admin area
wp_redirect( home_url() );
View pp-wp-snippet-stop-admin-redirect.php
// This code snippet stops WordPress from redirecting a variety of URLs to the admin area
remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
View pp-wp-snippet-hide-login-hints.php
// This code snippet prevents WordPress from giving hints on incorrect logins
// Add a custom function to filter the login error message
add_filter( 'login_errors', 'hide_login_hint' );
function hide_login_hint( $error ){
// No matter what error occurred always display the same message
return 'Login incorrect.';
View pp-wp-snippet-hide-exclusive-content.php
// This code snippet hides exclusive content if the user is not logged in
// To hide content you have to create a category with the slug 'only-for-members'
// All posts assigned to this category will be hidden from not logged in users
// Add a custom function to filter the content
add_filter( 'the_content', 'exclusive_content', 99 );
// If the user is not logged in, the excerpt will be displayed plus a message that the content is avialable only for registered users
You can’t perform that action at this time.