WordPress Lexikon | 4.8 – Codeschnipsel

Hier findest du die Snippets aus dem Buch Kompendium für WordPress 4.8 zum kopieren.

Abonnent 1function fuege_abonnent_befaehigungen_hinzu() {
 2    $role = get_role( 'subscriber' );
 3    $role->add_cap( 'read_private_posts' );
 4    $role->add_cap( 'read_private_pages' );
 5}
 6add_action( 'init', 'fuege_abonnent_befaehigungen_hinzu' );⇒ #abonnent-1
Action Hooks 1function footer_text() {
 2    echo '<p style="text-align:center"><em>Code is poetry.</em></p>';
 3}
 4add_action( 'wp_footer', 'footer_text' );⇒ #action-hooks-1
 1do_action( 'mein_action_hook' );⇒ #action-hooks-2
 1function gebe_jahr_aus() {
 2    echo '&copy; ' . date( 'Y' );
 3}
 4add_action( 'mein_action_hook', 'gebe_das_jahr_aus' );⇒ #action-hooks-3
 1function entferne_footer_text(){
 2    remove_action( 'wp_footer', 'footer_text' );
 3}
 4add_action( 'init', 'entferne_footer_text' );⇒ #action-hooks-4
Administrator 1function author_page_redirect() {
 2    if ( is_author( 1 ) ) {
 3        wp_redirect( home_url() ); exit;
 4    }
 5}
 6add_action( 'template_redirect', 'author_page_redirect' );⇒ #administrator-1
 1add_filter( 'rest_endpoints', function( $endpoints ) {
 2    if ( isset( $endpoints['/wp/v2/users'] ) ) {
 3        unset( $endpoints['/wp/v2/users'] );
 4    }
 5    if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
 6        unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
 7    }
 8    return $endpoints;
 9} );⇒ #administrator-2
Aktualisierungen 1add_filter( 'automatic_updater_disabled', '__return_true' );⇒ #aktualisierungen-1
 1define( 'WP_AUTO_UPDATE_CORE', true );⇒ #aktualisierungen-2
 1define( 'AUTOMATIC_UPDATER_DISABLED', true );⇒ #aktualisierungen-3
 1function hide_wp_update_nag() {
 2    remove_action( 'admin_notices', 'update_nag', 3 );
 3    remove_filter( 'update_footer', 'core_update_footer' );
 4}
 5add_action( 'admin_menu', 'hide_wp_update_nag' );⇒ #aktualisierungen-4
Anhang-Seite 1function anhangseite_noindex() {
 2    if ( is_attachment() ) {
 3        wp_no_robots();
 4    }
 5}
 6add_action( 'wp_head', 'anhangseite_noindex' );⇒ #anhang-seite-1
 1function weiterleitung_anhangseite() {
 2    global $post;
 3    if ( is_attachment() && isset( $post->post_parent ) && is_numeric( $post->post_parent ) && ( $post->post_parent != 0 ) ) {
 4        wp_redirect( get_permalink( $post->post_parent ), 301 );
 5        exit();
 6    }
 7}
 8add_action( 'template_redirect', 'weiterleitung_anhangseite' );⇒ #anhang-seite-2
Anpassungen 1function hinweis_zur_anpassung() {
 2    if ( ! is_user_logged_in() ) {
 3        wp_die( 'Die Website ist ab 10 Uhr wieder erreichbar.' );
 4    }
 5}
 6add_action( 'get_header', 'hinweis_zur_anpassung' );⇒ #anpassungen-1
 1<body class="page page-id-123 page-template-default">
 2    <article id="post-123" class="post-123 page type-page status-publish hentry">⇒ #anpassungen-2
 1.page .sidebar {
 2    display: none;
 3}⇒ #anpassungen-3
 1<?php /* get_sidebar(); */ ?>⇒ #anpassungen-4
 1function remove_content_sidebar() {
 2    if ( is_page() ) {
 3        $sidebars_widgets['SEITENLEISTE'] = false;
 4    }
 5    return $sidebars_widgets;
 6}
 7add_action( 'sidebars_widgets', 'remove_content_sidebar', 11 );⇒ #anpassungen-5
Archivseite 1add_filter( 'get_the_archive_title', function ( $title ) {
 2    return preg_replace( '#^\w+: #', '', $title );
 3} );⇒ #archivseite-1
 1<?php echo types_render_termmeta( "FIELD-SLUG", array( "width" => "300", "height" => "200" ) ); ?>⇒ #archivseite-2
 1<?php /* Template Name: Archivseite */ ?>
 2<?php get_header() ?>
 3    <?php the_title( '<h2>', '</h2>' ); ?>
 4    <h3>Die 5 neuesten Beiträge</h3>
 5        <?php wp_get_archives( 'type=postbypost&number=5' ); ?>
 6    <h3>Monatsarchiv</h3>
 7        <?php wp_get_archives(); ?>
 8    <h3>Alle Beiträge (alphabetisch geordnet)</h3>
 9        <?php wp_get_archives( 'type=alpha' ); ?>
10<?php get_footer() ?>⇒ #archivseite-3
Auszug 1function box_auszug_in_seiten() {
 2    add_post_type_support( 'page', 'excerpt' );
 3}
 4add_action( 'init', 'box_auszug_in_seiten' );⇒ #auszug-1
 1<?php if ( has_excerpt() || strpos( get_the_content(), 'more-link' ) === false ) { 
 2    the_excerpt();
 3    echo '<p><a class="more-link" href="'. get_permalink() . '">Weiterlesen</a></p>';
 4} else { 
 5    the_content( 'Weiterlesen', TRUE ); 
 6} ?>⇒ #auszug-2
 1function weiterlesen_hinweis( $more ) {
 2    return '';
 3}
 4add_filter( 'excerpt_more', 'weiterlesen_hinweis' );⇒ #auszug-3
 1function auszug_laenge( $length ) {
 2    return 200;
 3}
 4add_filter( 'excerpt_length', 'auszug_laenge', 999 );⇒ #auszug-4
Autor 1<div class="author-info">
 2    <h6><?php the_author_meta( 'nickname' ) ?></h6>
 3    <p><?php the_author_meta( 'description' ); ?></p>
 4</div>⇒ #autor-1
 1function zeige_alle_autoren( $content ) {
 2    if ( is_single() ) {
 3        if ( function_exists( 'coauthors_posts_links' ) ) {
 4            coauthors_posts_links( ', ', ' und ', '<div class="co-authors-plus">von ', '</div>' );
 5        } else { the_author_posts_link(); }
 6    } 
 7    return $content; 
 8}
 9add_filter( 'the_content', 'zeige_alle_autoren' );⇒ #autor-2
 1body.archive.author-dolly article h2 a {
 2    color: deeppink;
 3}⇒ #autor-3
Autosave 1define( 'AUTOSAVE_INTERVAL', 1800 );⇒ #autosave-1
 1function deaktiviere_autosave() {
 2    wp_deregister_script( 'autosave' ); 
 3} 
 4add_action( 'wp_print_scripts', 'deaktiviere_autosave' );⇒ #autosave-2
Beiträge 1function reihenfolge_in_beitraegen() {
 2    add_post_type_support( 'post', 'page-attributes' );
 3}
 4add_action( 'admin_init', 'reihenfolge_in_beitraegen' );⇒ #beitraege-1
Beitragsbild 1function open_graph_vorschaubild() {
 2    $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full');
 3    if ( $src ) : 
 4        echo '<meta property="og:image" content="' . $src[0] . '"/><meta property="og:image:secure_url" content="' . $src[0] . '"/><meta property="og:image:width" content="' . $src[1] . '"/><meta property="og:image:height" content="' . $src[2] . '"/><meta name="twitter:image" content="' . $src[0] . '"/>';
 5    endif; 
 6}
 7add_action( 'wp_head', 'open_graph_vorschaubild' );⇒ #beitragsbild-1
Beitragsformate 1function alle_beitragsformate() {
 2    add_theme_support( 'post-formats', array( 'aside', 'chat', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio' ) ); 
 3}
 4add_action( 'after_setup_theme', 'alle_beitragsformate', 11 );⇒ #beitragsformate-1
 1.format-quote .entry-title {
 2    display: none;
 3}⇒ #beitragsformate-2
 1<?php $tax_key = 'post_format';
 2if ( has_term( '', $tax_key ) ) {
 3    echo 'Beitragsformat: ' . get_the_term_list( $post->ID, $tax_key, '', ', ', ''); 
 4} ?>⇒ #beitragsformate-3
 1<?php while ( have_posts() ) : the_post();
 2    get_template_part( 'content', get_post_format() );
 3    comments_template();
 4endwhile; ?>⇒ #beitragsformate-4
Benutzerdefinierte Felder 1<p><?php echo get_post_meta( get_the_ID(), 'NAME-DES-BENUTZERDEFINIERTEN-FELDES', true ); ?></p>⇒ #benutzerdefinierte-felder-1
 1<?php $header_url = get_post_meta( get_the_ID(), 'Header-URL', true );
 2if ( !empty( $header_url ) ) {
 3        echo '<img src="' . $header_url . '" />';
 4} ?>⇒ #benutzerdefinierte-felder-2
Benutzer-Rolle 1// Entferne Rolle: Mitarbeiter
 2remove_role( 'contributor' );
 3// Erstelle Rolle: Kunde
 4add_role( 'leser', __( 'Leser' ), array(
 5 'read_private_posts' => true,
 6 'read_private_pages' => true ) );⇒ #benutzer-rolle-1
Blogseiten 1function max_beitrage_in_kategorie_reise( $query ) {
 2    if ( ! is_admin() && $query->is_main_query() ){
 3        if ( is_category( 'Reise' ) ){
 4            $query->set( 'posts_per_page', 3 );
 5        }
 6    }
 7}
 8add_action( 'pre_get_posts', 'max_beitrage_in_kategorie_reise' );⇒ #blogseiten-1
Button-Lösung 1function change_wc_strings( $translated_text, $text, $domain ) {
 2    switch ( $translated_text ) {
 3        case 'Bestellung abschicken' :
 4            $translated_text = __( 'Zahlungspflichtig Bestellen', 'woocommerce' );
 5        break;
 6        case 'Weiter zu PayPal' :
 7            $translated_text = __( 'Zahlungspflichtig Bestellen', 'woocommerce' );
 8        break;
 9    }
10    return $translated_text;
11}
12add_filter( 'gettext', 'change_wc_strings', 20, 3 );⇒ #button-loesung-1
Child Theme 1/* Theme Name: Child Theme vom Theme XY
 2   Template: xy-theme-textdomain */⇒ #child-theme-1
 1function theme_enqueue_styles() {
 2    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
 3    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) );
 4}
 5add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );⇒ #child-theme-2
Codeschnipsel 1require get_template_directory() . '/inc/customizer.php';⇒ #codeschnipsel-1
Cookie 1remove_action( 'set_comment_cookies', 'wp_set_comment_cookies' );⇒ #cookie-1
 1function change_embed_oembed_html_cache( $cache, $url, $attr, $post_ID ) {
 2    return str_replace( 'www.youtube.com', 'www.youtube-nocookie.com', $cache );
 3}
 4add_filter( 'embed_oembed_html', 'change_embed_oembed_html_cache', 10, 4 );⇒ #cookie-2
Cronjob 1define( 'DISABLE_WP_CRON', true );⇒ #cronjob-1
CSS 1a.excerpt-more-link {
 2   padding: .5em;
 3   border-radius: .25em;
 4   background: #000000; /* schwarz */
 5   color: #ffffff; /* weiss */
 6}⇒ #css-1
 1<body <?php body_class(); ?>>⇒ #css-2
 1<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>⇒ #css-3
 1.category-reise a.excerpt-more-link { 
 2    background: red;
 3}⇒ #css-4
Custom Post Types 1function portfolio_post_type() {
 2    $args = array( 'public' => true,
 3                   'label' => 'Portfolio',
 4                   'menu_icon' => 'dashicons-format-gallery',
 5                   'has_archive' => true,
 6                   'menu_position' => 5,
 7                   'supports' => array( 'editor', 'title', 'thumbnail' ) );
 8    register_post_type( 'portfolio', $args );
 9}
10add_action( 'init', 'portfolio_post_type' );⇒ #custom-post-types-1
Dashboard 1function remove_dashboard_widgets() {
 2    remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); 
 3}
 4add_action( 'wp_dashboard_setup', 'remove_dashboard_widgets' );⇒ #dashboard-1
 1function box_inhalt( $post, $callback_args ) {
 2    echo 'Einen neuen Beitrag kannst du <a rel="nofollow" href="post-new.php">hier</a> schreiben.';
 3}
 4function add_dashboard_widgets() {
 5    wp_add_dashboard_widget( 'box_hallo', 'Hallo!', 'box_inhalt' );
 6}
 7add_action( 'wp_dashboard_setup', 'add_dashboard_widgets' );⇒ #dashboard-2
Datenbank 1define( 'DB_NAME', 'wZtdr45Tr12' );
 2define( 'DB_USER', 'TfsrNgrE19T' );
 3define( 'DB_PASSWORD', '!9TffD2&dR_o' );⇒ #datenbank-1
 1define( 'WP_ALLOW_REPAIR', true );⇒ #datenbank-2
Debug-Modus 1// Der Debug-Modus ist aktiv.
 2define( 'WP_DEBUG', true );⇒ #debug-modus-1
 1// Der Debug-Modus ist deaktiviert.
 2define( 'WP_DEBUG', false );⇒ #debug-modus-2
Duplicate Content 1function add_meta_robots_noindex_follow(){
 2    if ( is_archive() || is_paged() || is_search() || is_attachment() || is_404() ) {
 3        wp_no_robots();
 4    }
 5}
 6add_action( 'wp_head', 'add_meta_robots_noindex_follow' );⇒ #duplicate-content-1
editor-style.css 1function editor_style_css() {
 2    add_editor_style();
 3}
 4add_action( 'admin_init', 'editor_style_css' );⇒ #editor-style-css-1
 1<?php 
 2// Plugin Name: Eigene editor-style.css
 3function editor_style_css( $mce_css ) {
 4    if ( ! empty( $mce_css ) )
 5        $mce_css .= ',';
 6        $mce_css .= plugins_url( 'editor-style.css', __FILE__ );
 7        return $mce_css;
 8}
 9add_filter( 'mce_css', 'editor_style_css' );⇒ #editor-style-css-2
Emoji 1function entferne_emojis() {
 2    remove_filter( 'the_content', 'convert_smilies' );
 3    add_filter( 'emoji_svg_url', '__return_false' );
 4    remove_action( 'wp_print_styles', 'print_emoji_styles' );
 5    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
 6    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
 7    remove_action( 'admin_print_styles', 'print_emoji_styles' );
 8}
 9add_action( 'init', 'entferne_emojis' );⇒ #emoji-1
Erweiterte Menüeigenschaften 1a[href*="wordpress.org"] {
 2    color: royalblue;
 3}⇒ #erweiterte-menueeigenschaften-1
 1function link_beschreibung( $item_output, $item, $depth, $args ) {
 2    if ( isset( $args->theme_location ) && !empty( $item->description ) ) {
 3        $item_output = $item_output . '<div class="link-description">' . $item->description . '</div>';
 4    }
 5    return $item_output;
 6}
 7add_filter( 'walker_nav_menu_start_el', 'link_beschreibung', 10, 4 );⇒ #erweiterte-menueeigenschaften-2
Filter Hooks 1function inhalt_mod_datum( $content ) {
 2    if ( is_single() ) {
 3        $content = '<p>Der Beitrag wurde am '. get_the_modified_date( 'j. F Y' ) . ' bearbeitet.</p>' . $content;
 4    } 
 5    return $content;
 6}
 7add_filter( 'the_content', 'inhalt_mod_datum' );⇒ #filter-hooks-1
FOUC 1function no_fouc(){
 2    echo '<style type="text/css">.no-fouc{display:none;}</style><script>document.documentElement.className="no-fouc";</script>';
 3}
 4add_action( 'wp_head', 'no_fouc' );
 5
 6function show_content(){
 7    echo '<script>document.documentElement.classList.remove("no-fouc");</script>';
 8}
 9add_action( 'wp_footer', 'show_content' );⇒ #fouc-1
GPL 1/* 
 2License: GNU General Public License v2 or later
 3License URI: http://www.gnu.org/licenses/gpl-2.0.html
 4*/⇒ #gpl-1
Gravatar 1echo get_avatar( get_the_author_meta( 'user_email' ) );⇒ #gravatar-1
.htaccess-Datei 1# BEGIN WordPress
 2<IfModule mod_rewrite.c>
 3RewriteEngine On
 4RewriteBase /
 5RewriteRule ^index\.php$ - [L]
 6RewriteCond %{REQUEST_FILENAME} !-f
 7RewriteCond %{REQUEST_FILENAME} !-d
 8RewriteRule . /index.php [L]
 9</IfModule>
10# END WordPress⇒ #htaccess-datei-1
HTML 1<!DOCTYPE html>
 2<html lang="de">
 3    <head>
 4        <meta charset="utf-8">
 5        <title>TITEL</title>
 6    </head>
 7    <body>
 8        <h1>Überschrift</h1>
 9        <p>Ich bin ein Absatz.</p>
10    </body>
11</html>⇒ #html-1
 1<a style="background-color:black; color:white; text-decoration:none; padding:1em; font-family:arial; border-radius:0.5em;" href="https://WEBSITE.EXAMPLE">BUTTON</a>⇒ #html-2
 1<a class="button" href="https://WEBSITE.EXAMPLE">BUTTON</a>⇒ #html-3
.htpasswd-Datei 1benutzername:$apr1$vQ7oakX2$Bo/.Uuoakf.A5nfrGnfwr0⇒ #htpasswd-datei-1
 1<Files wp-login.php>
 2 AuthName "Basisauthentifizierung"
 3 AuthType Basic
 4 AuthUserFile /ABSOLUTER-PFAD/.htpasswd
 5 Require valid-user
 6</Files>⇒ #htpasswd-datei-2
 1<?php echo dirname(__FILE__) . "/.htpasswd"; ?>⇒ #htpasswd-datei-3
 1add_filter( 'xmlrpc_enabled', '__return_false' );⇒ #htpasswd-datei-4
Impressum 1a.impressum, a[href*="impressum"] {
 2    color: black;
 3}⇒ #impressum-1
Indexierung 1<meta name="robots" content="noindex, follow">⇒ #indexierung-1
 1function noimageindex() {
 2    echo '<meta name="robots" content="noimageindex">';
 3}
 4add_action( 'wp_head', 'noimageindex' );⇒ #indexierung-2
 1add_action( 'wp_head', function() {
 2    echo '<meta name="google-site-verification" content="ABC-123_xyz" />'; } );⇒ #indexierung-3
Jetpack 1add_filter( 'jetpack_development_mode', '__return_true' );⇒ #jetpack-1
Kanonische URL 1<link rel="canonical" href="https://WEBSITE.EXAMPLE/" />⇒ #kanonische-url-1
 1function noindex_fuer_kommentare() {
 2    global $cpage;
 3    if ( $cpage >= 1 )
 4        wp_no_robots();
 5}
 6add_action( 'wp_head', 'noindex_fuer_kommentare' );⇒ #kanonische-url-2
Kategorie 1body.archive.category.category-reisen {
 2   background-image: url("https://WEBSITE.EXAMPLE/wp-content/uploads/BILD.jpg");
 3}⇒ #kategorie-1
Kommentar 1function speicher_keine_ip( $comment_author_ip ){
 2    return '';
 3}
 4add_filter( 'pre_comment_user_ip', 'speicher_keine_ip' );⇒ #kommentar-1
 1remove_action( 'set_comment_cookies', 'wp_set_comment_cookies' );⇒ #kommentar-2
Kurzlink 1function kurzlink_schaltflaeche( $shortlink ) {
 2    return $shortlink;
 3}
 4add_filter( 'get_shortlink', 'kurzlink_schaltflaeche' );⇒ #kurzlink-1
 1<?php echo '<p>Kurzlink: <a rel="nofollow" href="' . wp_get_shortlink() . '">' . wp_get_shortlink() . '</a></p>'; ?>⇒ #kurzlink-2
 1function fuege_kurzlink_hinzu( $content ){
 2    if ( is_single() ){
 3        $content = $content . '<p>Kurzlink: <a rel="nofollow" href="' . wp_get_shortlink() . '">' . wp_get_shortlink() . '</a></p>';
 4    }
 5    return $content;
 6}
 7add_filter( 'the_content', 'fuege_kurzlink_hinzu' );⇒ #kurzlink-3
 1<link rel="shortlink" href="https://WEBSITE.EXAMPLE/?p=123" />⇒ #kurzlink-4
 1remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );⇒ #kurzlink-5
Link-Benachrichtigung 1function no_self_ping( &$links ) {
 2    $home = get_option( 'home' );
 3    foreach ( $links as $l => $link )
 4        if ( 0 === strpos( $link, $home ) )
 5            unset( $links[$l] );
 6}
 7add_action( 'pre_ping', 'no_self_ping' );⇒ #link-benachrichtigung-1
Linkmanager 1add_filter( 'pre_option_link_manager_enabled', '__return_true' );⇒ #linkmanager-1
Login 1function login_hinweise_entfernen() {
 2    return '';
 3}
 4add_filter( 'login_errors', 'login_hinweise_entfernen' );⇒ #login-1
Login Timeout 1function ein_jahr_eingeloggt( $expire ) {
 2    return 31556926; // 1 Jahr in Sekunden
 3}
 4add_filter( 'auth_cookie_expiration', 'ein_jahr_eingeloggt' );⇒ #login-timeout-1
Loop 1<?php if ( have_posts() ) : ?>
 2    <?php while ( have_posts() ) : the_post(); ?>
 3            <h1><?php the_title() ?></h1>
 4            <div><?php the_content() ?></div>
 5    <?php endwhile; ?>
 6<?php endif; ?>⇒ #loop-1
 1<?php if ( have_posts() ) :
 2    while ( have_posts() ) : the_post();
 3        get_template_part( 'content', get_post_format() );
 4    endwhile;
 5else : ?>
 6    <p><?php _e( 'No results were found.', 'theme_textdomain' ); ?></p>
 7<?php endif; ?>⇒ #loop-2
Mediathek 1define( 'UPLOADS', 'wp-content/medien' );⇒ #mediathek-1
Mehrsprachigkeit 1<link rel="alternate" href="https://de.WEBSITE.EXAMPLE/" hreflang="de" />
 2<link rel="alternate" href="https://en.WEBSITE.EXAMPLE/" hreflang="en-GB" />⇒ #mehrsprachigkeit-1
Meta Box 1function entferne_box_auszug() {
 2    remove_meta_box( 'postexcerpt', 'page', 'normal' ); 
 3}
 4add_action( 'admin_menu', 'entferne_box_auszug' );⇒ #meta-box-1
Multisite 1define( 'WP_ALLOW_MULTISITE', true );⇒ #multisite-1
Newsfeed 1<a href="<?php bloginfo( 'atom_url' ); ?>"><img src="https://WEBSITE.EXAMPLE/feed-icon.png" width="50" height="50" class="feed-icon" alt="Feed Icon"></a>⇒ #newsfeed-1
 1add_theme_support( 'automatic-feed-links' );⇒ #newsfeed-2
 1function newsfeed_podcast() {
 2    echo '<link rel="alternate" type="application/rss+xml" title="Podcast" href="https://WEBSITE.EXAMPLE/category/podcast/feed" />'; 
 3}
 4add_action( 'wp_head', 'newsfeed_podcast' );⇒ #newsfeed-3
 1<link title="&#127911; Podcast" rel="alternate" type="application/rss+xml" href="https://WEBSITE.EXAMPLE/category/podcast/feed" />⇒ #newsfeed-4
 1function feed_verweise_entfernen(){
 2    remove_action( 'wp_head', 'feed_links_extra', 3 );
 3    remove_action( 'wp_head', 'feed_links', 2 );
 4}
 5add_action( 'init', 'feed_verweise_entfernen' );⇒ #newsfeed-5
 1function kategorie_aus_dem_newsfeed( $query ) {
 2    if ( $query->is_feed ) {
 3         $query->set( 'category_name', 'CATEGORY-SLUG' );
 4    }
 5    return $query;
 6}
 7add_filter( 'pre_get_posts', 'kategorie_aus_dem_newsfeed' );⇒ #newsfeed-6
Page Template 1<?php /* Template Name: NAME DES SEITEN-TEMPLATES */ ?>⇒ #page-template-1
 1<?php /* Template Name: Ohne Seitenleiste
 2         Template Post Type: post */ ?>⇒ #page-template-2
Papierkorb 1define( 'EMPTY_TRASH_DAYS', 90 );⇒ #papierkorb-1
Passwort 1<?php wp_set_password( "MEIN-PASSWORT", 123 ); ?>⇒ #passwort-1
Performance 1User-agent: *
 2Disallow: /wp-content/cache/
 3Allow: /⇒ #performance-1
 1function add_defer( $tag, $handle ) { 
 2    if ( is_admin() ) {
 3        return $tag;
 4    }
 5    return str_replace( ' src', ' defer src', $tag );
 6}
 7add_filter( 'script_loader_tag', 'add_defer', 10, 2 );⇒ #performance-2
Permalink 1# BEGIN WordPress
 2<IfModule mod_rewrite.c>
 3RewriteEngine On
 4RewriteBase /
 5RewriteRule ^index\.php$ - [L]
 6RewriteCond %{REQUEST_FILENAME} !-f
 7RewriteCond %{REQUEST_FILENAME} !-d
 8RewriteRule . /index.php [L]
 9</IfModule>
10# END WordPress⇒ #permalink-1
Plugin-Entwicklung 1define( 'WP_DEBUG', true );⇒ #plugin-entwicklung-1
 1<?php /* Plugin Name: DEIN PLUGIN NAME
 2         Description: Das Plugin macht... */ ?>⇒ #plugin-entwicklung-2
 1<?php if ( ! defined( 'ASPATH' ) ) { exit; } ?>⇒ #plugin-entwicklung-3
 1<?php function link_in_werkzeugleiste( $wp_admin_bar ) {
 2    if ( current_user_can( 'edit_plugins' ) ) {
 3        $wp_admin_bar->add_node( 
 4            array( 'id' => 'custom-plugin', 
 5                   'title' => 'Custom Plugin', 
 6                   'href' => self_admin_url( 'plugin-editor.php?plugin=custom-plugin%2Fcustom-plugin.php&scrollto=200' ) ) );
 7    } 
 8} 
 9add_action( 'admin_bar_menu', 'link_in_werkzeugleiste', 999 );⇒ #plugin-entwicklung-4
Redakteur 1function remove_editor_capabilities() {
 2    $editor = get_role( 'editor' );
 3    $caps = array( 'read_private_pages', 'delete_private_pages', 'edit_private_pages', 'read_private_posts', 'delete_private_posts', 'edit_private_posts' );
 4    foreach ( $caps as $cap ) {
 5        $editor->remove_cap( $cap );
 6    }
 7}
 8add_action( 'init', 'remove_editor_capabilities' );⇒ #redakteur-1
Responsive Image Support 1<img class="alignnone bild-32 size-full" src="https://website.example/sonne.jpg" alt="Sonne" width="413" height="213" srcset="https://website.example/sonne.jpg 413w, https://website.example/sonne-300x155.jpg 300w" sizes="(max-width: 413px) 100vw, 413px"/>⇒ #responsive-image-support-1
 1function deaktiviere_srcset( $sources ) {
 2    return false;
 3}
 4add_filter( 'wp_calculate_image_srcset', 'deaktiviere_srcset' );⇒ #responsive-image-support-2
Responsive Webdesign 1.sidebar-left { float: right; }
 2
 3@media (min-width: 450px) and (max-width: 950px) {
 4    .sidebar-left { float: none; } 
 5}⇒ #responsive-webdesign-1
 1<link rel="stylesheet" type="text/css" href="print.css" media="print">⇒ #responsive-webdesign-2
 1<meta name="viewport" content="width=device-width, initial-scale=1.0">⇒ #responsive-webdesign-3
Revisionen 1define( 'WP_POST_REVISIONS', 5 );⇒ #revisionen-1
 1function anzahl_der_revisionen( $num ) {
 2    return 5;
 3}
 4add_filter( 'wp_revisions_to_keep', 'anzahl_der_revisionen' );⇒ #revisionen-2
robots.txt 1User-agent: *
 2# Crawling verhindern
 3Disallow: /⇒ #robots-txt-1
 1User-agent: *
 2# Crawling der Bilder verhindern
 3Disallow: /*.jpeg$
 4Disallow: /*.jpg$⇒ #robots-txt-2
 1User-agent: *
 2# Crawling verhindern
 3Disallow: /admin/
 4Disallow: /wp-admin/
 5Disallow: /wp-includes/
 6Disallow: /wp-content/
 7# Crawling erlauben
 8Allow: /wp-content/uploads/
 9Allow: /wp-content/themes/*.js
10Allow: /wp-content/themes/*.css
11Allow: /wp-content/cache/*.js
12Allow: /wp-content/cache/*.css
13Allow: /wp-includes/*.js
14Allow: /wp-includes/*.css⇒ #robots-txt-3
 1<meta name="robots" content="noindex, follow" />⇒ #robots-txt-4
 1function fuege_noindex_hinzu() {
 2    if ( is_page( 'Sonderangebot' ) )
 3        wp_no_robots();
 4}
 5add_action( 'wp_head', 'fuege_noindex_hinzu' );⇒ #robots-txt-5
Schlagwörter 1body.archive.tag.tag-venedig {
 2   background-image: url("https://WEBSITE.EXAMPLE/wp-content/uploads/BILD.jpg");
 3}⇒ #schlagwoerter-1
Schlagwörter-Wolke 1function alle_schlagwoerter_ausgeben( $args ) {
 2    $args = array( 'number' => 0 );
 3    return $args;
 4}
 5add_filter( 'widget_tag_cloud_args','alle_schlagwoerter_ausgeben' );⇒ #schlagwoerter-wolke-1
 1function kategorie_wolke_shortcode() {
 2    $wolke = wp_tag_cloud( array( 'taxonomy' => 'category', 'echo' => false ) );
 3    return '<div class="wolke">' . $wolke . '</div>';
 4}
 5add_shortcode( 'kategorie-wolke', 'kategorie_wolke_shortcode' );⇒ #schlagwoerter-wolke-2
Seiten 1function boxen_in_seiten() {
 2    add_post_type_support( 'page', array( 'post-formats', 'excerpt', 'trackbacks' ) ); 
 3}
 4add_action( 'init', 'boxen_in_seiten' );⇒ #seiten-1
Seitenleiste 1function meine_seitenleiste() {
 2    register_sidebar(
 3        array(
 4            'name' => 'Seitenleiste',
 5            'description' => 'Widgets hier hinzufügen… '
 6        )
 7    );
 8}
 9add_action( 'widgets_init', 'meine_seitenleiste' );⇒ #seitenleiste-1
 1function meine_seitenleisten() {
 2    register_sidebars( 2, array( 
 3        'name' => 'Seitenleiste %d'
 4    ) );
 5}
 6add_action( 'widgets_init', 'meine_seitenleisten' );⇒ #seitenleiste-2
 1<?php if ( is_active_sidebar( 'Seitenleiste' ) ) { ?>
 2    <ul class="sidebar">
 3        <?php dynamic_sidebar( 'Seitenleiste' ); ?>
 4    </ul>
 5<?php } ?>⇒ #seitenleiste-3
Shortcode 1add_filter( 'the_title', 'do_shortcode' );⇒ #shortcode-1
 1add_filter( 'widget_text', 'shortcode_unautop' );
 2add_filter( 'widget_text', 'do_shortcode' );⇒ #shortcode-2
 1<?php echo do_shortcode( "[SHORTCODE]" ); ?>⇒ #shortcode-3
 1/* [space] */
 2function shortcode_leerschritt( $atts ){
 3    return '&nbsp;';
 4}
 5add_shortcode( 'space', 'shortcode_leerschritt' );⇒ #shortcode-4
 1/* [btn] DEIN TEXT [/btn] */
 2function shortcode_schaltflaeche( $atts, $content = null ) {
 3    return '<button onclick="location=\'https://WEBSITE.EXAMPLE\'">' . do_shortcode( $content ) . '</button>';
 4}
 5add_shortcode( 'btn', 'shortcode_schaltflaeche' );⇒ #shortcode-5
 1/* [platzhalter] oder [platzhalter hoehe="1em"] */
 2function platzhalter_shortcode( $atts ) {
 3    $a = shortcode_atts( array( 'abstand' => '1em' ), $atts ); 
 4    return '<div style="height:' . esc_attr( $a['abstand'] ) . '"></div>';
 5}
 6add_shortcode( 'platzhalter', 'platzhalter_shortcode' );⇒ #shortcode-6
 1function entferne_shortcode() {
 2    remove_shortcode( 'EXAMPLE' );
 3}
 4add_action( 'init', 'entferne_shortcode');⇒ #shortcode-7
Sicherheitsschlüssel 1define( 'AUTH_KEY', '123XYZ*!' );
 2define( 'SECURE_AUTH_KEY', '123XYZ*!' );
 3define( 'LOGGED_IN_KEY', '123XYZ*!' );
 4define( 'NONCE_KEY', '123XYZ*!' );
 5define( 'AUTH_SALT', '123XYZ*!' );
 6define( 'SECURE_AUTH_SALT', '123XYZ*!' );
 7define( 'LOGGED_IN_SALT', '123XYZ*!' );
 8define( 'NONCE_SALT', '123XYZ*!' );⇒ #sicherheitsschluessel-1
SSL-Zertifikat 1<IfModule mod_rewrite.c>
 2 RewriteEngine On
 3 RewriteCond %{HTTPS} !=on
 4 RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
 5</IfModule>⇒ #ssl-zertifikat-1
Sticky Post 1.sticky {
 2    background: linear-gradient(to right, #9C27B0 0%, #E91E63 100%);
 3}⇒ #sticky-post-1
style.css 1/* 
 2Theme Name: Theme-Name
 3Theme URI: https://www.website.example
 4Author: Theme-Entwickler-Name
 5Author URI: https://www.website.example
 6Description: This is a theme for your blog.
 7Version: 1.0
 8Text Domain: theme-name
 9License: GNU General Public License v2 or later
10License URI: https://www.gnu.org/licenses/gpl-2.0.html
11Tags: 
12*/⇒ #style-css-1
 1/*
 2Theme Name: Child-Theme-Name
 3Template: Parent-Theme-Name
 4*/⇒ #style-css-2
 1function styles() { 
 2    wp_enqueue_style( 'theme-name-style', get_stylesheet_uri() );
 3}
 4add_action('wp_enqueue_style', 'styles');⇒ #style-css-3
Suche 1function punkt_get_search_form() {
 2    get_search_form();
 3}
 4add_action( 'wp_footer', 'punkt_get_search_form' );⇒ #suche-1
 1function punkt_adapt_search_form( $form ) {
 2    $form = str_replace( 'Suche nach:', '', $form );
 3    return $form;
 4}
 5add_filter( 'get_search_form', 'punkt_adapt_search_form' );⇒ #suche-2
 1<?php /* Template Name: Search Page */ ?>
 2<?php get_header(); ?>
 3    <div id="primary" class="content-area">
 4        <main id="main" class="site-main" role="main">
 5            <?php get_search_form(); ?>
 6        </main>
 7    </div>
 8<?php get_footer(); ?>⇒ #suche-3
 1function search_filter( $query ) {
 2   if ( ! is_admin() && $query->is_main_query() ) {
 3      if ( $query->is_search ) {
 4         $query->set( 'post_type', 'post' );
 5      }
 6   }
 7}
 8add_action( 'pre_get_posts','search_filter' );⇒ #suche-4
Tastaturkürzel 1u {
 2    background: pink; /* rosafarbener Hintergrund */
 3    text-decoration: none; /* nicht unterstreichen */
 4}⇒ #tastaturkuerzel-1
Taxonomien 1function taxonomie_status() {
 2    $args = array( 'label' => __( 'Status' ),
 3        'hierarchical' => true,
 4        'rewrite' => array( 'slug' => 'status' ),
 5        'show_admin_column' => true,
 6        'labels' => array ( 'add_new_item' => __( 'Neuen Status erstellen' ) ) );
 7    register_taxonomy( 'status', array( 'post', 'page'), $args ); 
 8}
 9add_action( 'init', 'taxonomie_status' );⇒ #taxonomien-1
 1<?php if ( is_tax( 'status' ) ) {
 2    echo 'Archiv der Custom Taxonomy: Status';
 3} elseif ( is_tax( 'post_format','gallery' ) ) {
 4    echo 'Archiv des Beitragsformates: Galerie';
 5} else {
 6    echo 'Etwas anderes.';
 7} ?>⇒ #taxonomien-2
 1<?php $tax_key = 'status';
 2    if( has_term( '', $tax_key ) ) {
 3        echo 'Status: ' . get_the_term_list( $post->ID, $tax_key, '', ', ', ''); 
 4    } ?>⇒ #taxonomien-3
Template Tags 1<?php get_header(); ?>
 2<?php get_sidebar(); ?>
 3<?php get_footer(); ?>⇒ #template-tags-1
 1<div class="entry-summary">
 2    <?php the_excerpt(); ?>
 3</div><!-- .entry-summary -->⇒ #template-tags-2
 1<p>von <?php the_author(); ?></p>
 2<p><?php the_author_meta( 'user_description' ); ?></p>⇒ #template-tags-3
 1<?php wp_list_bookmarks( 'title_li=&categorize=0' ); ?>⇒ #template-tags-4
 1<p>Kategorie: <?php the_category( ', ' ); ?></p>
 2<p>Schlagwörter: <?php the_tags( ' ', ', ', '' ); ?></p>⇒ #template-tags-5
 1<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
 2<?php edit_post_link( 'Bearbeiten', '<p>', '</p>' ); ?>⇒ #template-tags-6
 1<?php $author = get_the_author();
 2echo '<p>von ' . $author . '</p>'; ?>⇒ #template-tags-7
 1<?php require( get_template_directory() . '/inc/template-tags.php' ); ?>⇒ #template-tags-8
 1<?php if ( ! function_exists( 'mein_template_tag' ) ) :
 2    function mein_teaser_template_tag() {
 3        $teaser = get_post_meta( get_the_ID(), 'Teaser', true );
 4        if ( ! empty ( $teaser ) ) { 
 5            echo wpautop( $teaser ); 
 6        }
 7} endif; ?>⇒ #template-tags-9
 1<div class="entry-content">
 2    <?php mein_teaser_template_tag(); ?>
 3    <?php the_content(); ?>
 4</div><!-- .entry-content -->⇒ #template-tags-10
Text-Widget 1add_filter( 'widget_text', 'do_shortcode' );⇒ #text-widget-1
Theme-Entwicklung 1<!DOCTYPE html>
 2<html <?php language_attributes(); ?>>
 3    <head><?php wp_head(); ?></head>
 4    <body <?php body_class(); ?>>
 5        <?php if ( have_posts() ) :
 6            while ( have_posts() ) : the_post(); ?>
 7                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 8                    <h1><?php the_title() ?></h1>
 9                    <div><?php the_content() ?></div>
10                </article>
11            <?php wp_footer(); ?>
12        </body>
13</html>⇒ #theme-entwicklung-1
 1<header>
 2    <h1><a href="<?php bloginfo( 'url' ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
 3    <p><?php bloginfo( 'description' ); ?></p>
 4</header>⇒ #theme-entwicklung-2
 1require get_parent_theme_file_path( '/inc/customizer.php' );⇒ #theme-entwicklung-3
 1function themedomain_scripts() {
 2    wp_enqueue_style( 'themedomain-style', get_stylesheet_uri() );
 3    wp_enqueue_script( 'themedomain-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
 4}
 5add_action( 'wp_enqueue_scripts', 'themedomain_scripts' );⇒ #theme-entwicklung-4
 1if ( ! function_exists( 'themedomain_setup' ) ) :
 2    function themedomain_setup() {
 3        add_theme_support( 'title-tag' );
 4        add_theme_support( 'post-thumbnails' );
 5        add_theme_support( 'post-formats', array( 'quote', 'gallery') );
 6    }
 7endif;
 8add_action( 'after_setup_theme', 'themedomain_setup' );⇒ #theme-entwicklung-5
 1/*  
 2    Theme Name: THEME NAME
 3    Theme URI: https://WEBSITE.EXAMPLE/themedomain
 4    Author: NAME DES THEME ENTWICKLERS
 5    Author URI: https://WEBSITE.EXAMPLE
 6    Description: THEME NAME is a blogging theme.
 7    Version: 1.0
 8    License: GNU General Public License v2 or later
 9    License URI: http://www.gnu.org/licenses/gpl-2.0.html
10    Text Domain: themedomain
11    Tags: one-column, two-columns 
12*/⇒ #theme-entwicklung-6
Titel der Website 1<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
 2<p class="site-description"><?php bloginfo( 'description' ) ?></p>⇒ #titel-der-website-1
 1<?php $title = get_bloginfo( 'name' );
 2if (  $title && is_home() && !is_paged() ) :
 3    echo '<h1 class="site-title">' . $title .' </h1>';
 4elseif ( $title ) :
 5    echo '<h1 class="site-title"><a rel="nofollow" href="' . esc_url( home_url() ) . '" rel="home">' . $title . '</a></h1>';
 6endif;
 7
 8$description = get_bloginfo( 'description' );
 9if ( $description ) :
10    echo '<p class="site-description">' . $description . '</p>';
11endif; ?>⇒ #titel-der-website-2
 1h1.site-title {
 2   text-transform: uppercase; /* Großschreibung */
 3}
 4
 5p.site-description {
 6   font-style: italic; /* kursive Schriftlage */
 7}⇒ #titel-der-website-3
Umzug 1define( 'DB_NAME', 'DATENBANKNAME' );
 2define( 'DB_USER', 'DATENBANKBENUTZERNAME' );
 3define( 'DB_PASSWORD', 'DATENBANKPASSWORT' );⇒ #umzug-1
 1define( 'WP_SITEURL', 'https://WEBSITE.EXAMPLE' );
 2define( 'WP_HOME', 'https://WEBSITE.EXAMPLE' );⇒ #umzug-2
Weiterlesen-Link 1function weiterlesen_link(){
 2    return '<p><a class="more-link" href="' . get_permalink() . '">Weiterlesen</a></p>'; 
 3}
 4add_filter( 'the_content_more_link', 'weiterlesen_link' );
 5
 6function weiterlesen_link_excerpt( $excerpt ){
 7    if ( !is_admin() ){ $excerpt .= weiterlesen_link(); }
 8    return $excerpt;
 9}
10add_filter( 'get_the_excerpt', 'weiterlesen_link_excerpt' );⇒ #weiterlesen-link-1
 1function entferne_parent_theme_filter() {
 2    remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); 
 3    remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
 4}
 5add_action( 'after_setup_theme', 'entferne_parent_theme_filter' );⇒ #weiterlesen-link-2
 1a.more-link, a.more-link:hover, a.more-link:focus{
 2    background-image: url('https://WEBSITE.EXAMPLE/wp-content/uploads/BILD.png');
 3    background-size: 80px;
 4    background-repeat: no-repeat;
 5    border: none;
 6    color: transparent;
 7}⇒ #weiterlesen-link-3
Weiterlesen-Tag 1function entferne_more_link( $link ) {
 2    return preg_replace( '|#more-[0-9]+|', '', $link );
 3}
 4add_filter( 'the_content_more_link', 'entferne_more_link' );⇒ #weiterlesen-tag-1
WooCommerce 1function entferne_aehnliche_produkte(){
 2    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
 3 }
 4add_action( 'init', 'entferne_aehnliche_produkte', 10 );⇒ #woocommerce-1
 1function custom_related_products_args( $args ) {
 2    $args['posts_per_page'] = 6; // Produkte
 3    $args['columns'] = 3; // Reihen
 4    return $args;
 5}
 6add_filter( 'woocommerce_output_related_products_args', 'custom_related_products_args' );⇒ #woocommerce-2
 1function custom_wc_get_price_html( $price ) {
 2    if ( is_product_category( 'Schokolade' ) ){
 3        $price .= ' (inkl. 7 % USt.)';
 4    }
 5    return $price;
 6}
 7add_filter( 'woocommerce_get_price_html', 'custom_wc_get_price_html' );⇒ #woocommerce-3
WordPress-Installation 1# Zugang nur mit eigener IP
 2Order Deny,Allow
 3Deny from all
 4Allow from 12.345.6.78⇒ #wordpress-installation-1
wpautop 1remove_filter( 'the_content', 'wpautop' );
 2remove_filter( 'the_excerpt', 'wpautop' );⇒ #wpautop-1
wp-config.php 1define( 'DISALLOW_FILE_EDIT', true );⇒ #wp-config-php-1
 1define( 'WP_POST_REVISIONS', 3 );⇒ #wp-config-php-2
 1define( 'WP_DEBUG', false );⇒ #wp-config-php-3
 1define( 'WP_DEBUG', true );⇒ #wp-config-php-4
XML-Sitemap 1sitemap: https://WEBSITE.EXAMPLE/sitemap.xml⇒ #xml-sitemap-1
 1<IfModule mod_rewrite.c>
 2    <Files sitemap.xml>
 3        Header set X-Robots-Tag "noindex"
 4    </Files>
 5</IfModule>⇒ #xml-sitemap-2
Zugriffsrechte 1define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
 2define( 'FS_CHMOD_FILE', ( 0644 & ~ umask() ) );⇒ #zugriffsrechte-1

Zuletzt geändert am 05.07.2018 um 16:15:44 Uhr.