Skip to content

Instantly share code, notes, and snippets.

@pascalmaddin
pascalmaddin / redirect_commenter
Created June 11, 2013 08:36
WordPress - Redirect commenter to thank you post or page
<?php
add_filter('comment_post_redirect', 'redirect_after_comment');
function redirect_after_comment(){
wp_redirect('/thank-you-page/');
exit();
}
?>
@pascalmaddin
pascalmaddin / change_input_text
Created June 11, 2013 08:35
WordPress - Change default “Enter title here” text within post title input field
<?php
function title_text_input( $title ){
return $title = 'Enter new title';
}
add_filter( 'enter_title_here', 'title_text_input' );
?>
@pascalmaddin
pascalmaddin / add_lightbox_to_posts
Created June 11, 2013 08:34
WordPress - Add rel=”lightbox” to all images embedded in a post
<?php
add_filter('the_content', 'my_addlightboxrel');
function my_addlightboxrel($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
?>
@pascalmaddin
pascalmaddin / related_posts_by_author
Created June 11, 2013 08:32
WordPress - Display related posts by posts current author
@pascalmaddin
pascalmaddin / increase_excerpt_field
Created June 11, 2013 08:30
WordPress - Increase the excerpt field height
<?php
add_action('admin_head', 'excerpt_textarea_height');
function excerpt_textarea_height() {
echo'
<style type="text/css">
#excerpt{ height:500px; }
</style>
';
}
?>
@pascalmaddin
pascalmaddin / load_page_content.php
Last active December 15, 2015 00:59
WordPress - Loads the contents of another static page in WordPress
<?php
// Der Query für die Seite mit der ID 97 (als Beispiel)
$my_new_query = new WP_Query( 'page_id=97' );
// Loop starten
while ( $my_new_query->have_posts() ) : $my_new_query->the_post();
the_content();
endwhile;
// Und ein Reset - wichtig!
wp_reset_postdata();
?>