Beste Code-Sammlung für Ihre 'functions.php'-Datei
-
-
Bittefügen Sie auch Ihre alten,vorhandenen Erkenntnisse hinzu.Pleae add your old, existing findings as well.
- 0
- 2010-09-09
- hakre
-
Hallo * @ NetConstructor *: Ichbin besorgt über diese Frage,daes sich umeine "Liste der X" -Frage handelt,nach der die StackExchange-Leute Ausschau halten sollten: http://meta.stackexchange.com/questions/57226/should-we-have-a-list-of-x-close-reason Meinegroße Sorgeist,wennich an Ihre Frage denke,dassichmireine nahezu unendliche Anzahl von Antworten vorstellen kann,und als solchebin ichbesorgt,dass diese Frage zueiner Sammlung von Zufällenführen wirdAntworten,abernichts Bestimmtes.Ichmöchte die Meinung anderer dazueinholen,bevorich (stimme zu)es schließe. Daichjedochnicht hartnäckig seinmöchte,habeichnur Bedenken.Hi *@NetConstructor*: I'm concerned about this question because it's a "List of X" question the StackExchange people have told us to look out for: http://meta.stackexchange.com/questions/57226/should-we-have-a-list-of-x-close-reason My big concern is when I think of your question I can envision an almost infinite number of answers and as such I'm concerned that this question will result in a collection of random answers but nothing definitive. I want to get other's opinions on this before I (vote to) close it though as I don't want to be heavy handed, I just have concerns.
- 1
- 2010-09-09
- MikeSchinkel
-
Meine Stimmeistentwedernah oder Community WikimachenMy vote is either close or make community wiki
- 0
- 2010-09-09
- Chris_O
-
In Anbetracht der Tatsache,dass dieersten 5 Antworten vom OP stammen und die Frageeher darauf ausgerichtet zu sein scheint,eine Reihe von Antworten alseine einzigeendgültige Antwort zu sammeln,sollte diesein Community-Wiki sein.Considering the first 5 answers were by the OP and the question seems more geared at collecting an array of responses rather than a single, definitive answer, this should be a community wiki.
- 13
- 2010-09-09
- EAMann
-
Es scheint,dassmaneine Fragenichteinfachin ein Wiki ändern kann.Ist das richtig?seems that one can not just modify a question into a wiki. Is this correct?
- 0
- 2010-09-09
- NetConstructor.com
-
Trotzdemist diesnützlich (ich habe 2 Schnipselgefunden,dieich starknutzen werde),wennesein Community-Wiki sein soll undneugestartet werdenmuss,um das zutun. Vielleicht können wir das Zeugeinfach hierherbringen?Nonetheless this is useful (I have found 2 snippets I will be making heavy use of)if it's to be a community wiki and has to be started fresh to do that maybe we can just move the stuff here there?
- 1
- 2010-09-09
- Ashley G
-
@ NetConstructor.com ... Ich habe die Fragein ein Wiki umgewandelt,alsichmeinen letzten Kommentargeschrieben habe.Entschuldigung,wenn das Verwirrung stiftete.Normalerweise können Sie (als OP)eine Fragejederzeitin ein Wiki verwandeln.@NetConstructor.com ... I converted the question into a wiki when I wrote my last comment. Sorry if that caused any confusion. Normally, you (as the OP) can turn a question into a wiki at any time.
- 0
- 2010-09-10
- EAMann
-
@ EAMann danke ... Ich habenach dieser Optiongesucht,warmir abernicht sicher,wo sie sichbefindet.Vielleicht habeich die Optionnach der Konvertierungeinfachnichtmehrgesehen?@EAMann thanks... I was looking for that option but was not sure where it was located. Maybe after you converted it I just did not see the option anymore?
- 0
- 2010-09-10
- NetConstructor.com
-
*@NetConstructor.com* - Bingo.Sobaldes konvertiertist,istes konvertiert ... die Optionistfestgelegt und verschwindet von der Seite.*@NetConstructor.com* - Bingo. Once it's converted, it's converted ... the option is set and disappears from the page.
- 0
- 2010-09-10
- EAMann
-
Ich würde diesen schlechten Stilin Betracht ziehen und Pluginsbevorzugen.a) Sie werden vonengagierten Entwicklerngebaut.b) Sie werdengewartet und können leicht aufgerüstet werden.Für kleinebenutzerdefinierte Snippetsempfehleich das Plugin Shortcode Exec PHP,daseine sehr saubere undtragbare Möglichkeitbietet,Wordpress anzupassen.I would consider this bad style and prefer plugins. a) They are built by dedicated deveoplers b) they are maintained and easily upgraded. For little custom snippets I recommend the plugin Shortcode Exec PHP which yields a very clean -- and portable -- way to customize your Wordpress.
- 0
- 2010-11-10
- Raphael
-
Obwohlesinteressantist,glaubeich,dass diemeisten Leute zustimmen würden,dass Siebei der Entwicklung von Themen Dingein einer Dateifunctions.php lokalisierenmöchtenwhile interesting I believe most people would agree that when your developing themes you want things localized within a functions.php file
- 0
- 2010-11-24
- NetConstructor.com
-
@NetConstructor - Wenn Sie andere Einträgebearbeitenmöchten,können Siebitte darauf achten,dass Sie die Einrückungin meinem Beitrag verdorben haben. Ichbemühemichimmer,die Einrückungfür die Lesbarkeitbeizubehalten.Ich würdees auchbegrüßen,wenn Sie sich die Zeitnehmen könnten,die von Ihnen vorgenommenen Änderungen zuerläutern (ich konnte keinen Grundfür Ihre Bearbeitungmeines Eintragserkennen - undesgab keine Bearbeitungszusammenfassung).@NetConstructor - If you're going to edit others entries, can you please take care when doing so, you spoiled the indentation in my posting, i always make an effort to maintain indentation for readability. I'd also appreciate it if you could take the time to explain edits you make(i couldn't see any reason for your to edit my entry - and there was no edit summary).
- 0
- 2011-01-28
- t31os
-
@t31os - Ich habeesbearbeitet,umesmit allen Einträgen konsistent zu halten@t31os -- I edited it to keep it consistent with all of the entries
- 0
- 2011-02-07
- NetConstructor.com
-
Alle Antworten,die sichnicht aufein Themabeziehen,solltenentfernt werden.Dieser Threadistein gutes Beispielfür schlechte Codierungspraktiken.All answers not related to a theme should be removed. This thread is a good example for bad coding practices.
- 17
- 2011-06-13
- fuxia
-
Ich würdenicht zustimmenmüssen.Die Frage hattenichtsmit dem Thema zutun.Alle anwendbaren Funktionen. PHP-Mods sind willkommen und Benutzer solltenentsprechend abstimmen.I would have to disagree. Question was not related to the theme. All applicable functions.PHP mods are welcome and users should up/down vote accordingly.
- 1
- 2011-06-14
- NetConstructor.com
-
Esistinteressant,dassnirgendwoerwähnt wird,dass sich die Dateifunctions.phpin Ihrem Themenverzeichnisbefindet,was zu Verwirrungführt,wie zum Beispiel: http://wordpress.stackexchange.com/questions/25341/error-after-editing-functions-phpIt's interesting that it's not mentioned anywhere that the functions.php file is the one in your theme directory, leading to confusion, such as this: http://wordpress.stackexchange.com/questions/25341/error-after-editing-functions-php
- 1
- 2011-08-09
- scribu
-
Ich denke,es wärebesser,die Leute zuermutigen,[einbenutzerdefiniertes Funktions-Plugin zuerstellen] (http://www.doitwithwp.com/create-functions-plugin/),anstatt diefunctions.phpihres Themas zu verwendenI think it'd be better to encourage people to [create a custom functionality plugin](http://www.doitwithwp.com/create-functions-plugin/) instead of using their theme's functions.php
- 17
- 2012-01-16
- Ian Dunn
-
@Cor van Noorloos Die Nutzung des Community-Wiki-Status wurde vom Netzwerk stark reduziert undentmutigt.Einfach ausgedrückt: "Espasstnicht wirklich zur Qualitätssicherung,aberesistein Community-Wiki!"Entschuldigungfliegtnichtmehr.Die Antworten hier wurden ungeordnet und schlechtgepflegt,nur wegen Wow/Fun-Faktorbesucht.Überallim Netzwerk hatte sich vielbewegt,um Fragen wie diese zu quetschen.@Cor van Noorloos the use of community wiki status had been greatly reduced and discouraged by network. Simply put "it's not really good fit for QA, but it's community wiki!" excuse doesn't fly anymore. Answers here became disorderly and poorly maintained glob, only visited for wow/fun factor. There had been a lot of movement all over network to squash questions like this.
- 0
- 2012-02-19
- Rarst
-
In Bezug auf das Schließen dieses speziellen "Wikis" stimmeich dafür,dass dies wieder aufgenommen wird.Offensichtlichist dieser Wiki-Beitrag sehrbeliebt. Dies zeigt die Tatsache,dasser 30.000 Aufrufe hat,was dreimal so vielist wiejede andere Frage oderjedes andere Wiki auf dieser Website,und dass das Thema selbst 119 Mal hochgestimmt wurde,was doppelt so vielist wiebei jeder anderen Frageoder Thema.Wenn Siein seinem Werteinverstanden sind,stimmen Siebitte ab,umes wieder zu öffnen,indem Sie auf den Link "Wieder öffnen" klicken.In regards to the closing of this specific "wiki" I vote that this be reopend. Obviously this wiki post is highly popular demonstrated by the fact that it has 30,000 views which is three times the amount of ANY other question or wiki on this site and the topic itself has been up-voted 119 times which is double that of any other question or topic. If you agree in its value please vote to have it reopen by clicking the "reopen" link.
- 1
- 2012-02-20
- NetConstructor.com
-
@ NetConstructor.com Die reine Anzahl der Seitenaufrufeist kein Qualitätsindikator.Wir sollten spezifische Fragenmit spezifischen Antworten undguten Codierungspraktikenfördern.Dieser Threadist das Gegenteil.@NetConstructor.com The pure number of page views is not an indicator for quality. We should encourage specific questions with specific answers and good coding practices. This thread is the opposite.
- 3
- 2012-02-22
- fuxia
-
@toscho - dasistgenau der Grund,warum dies als Wikieingerichtet wurde und daher dieser Beitrag vollkommengültigist.Der Punkt,denichin Bezug auf Seitenaufrufegemacht habe,wurdeerwähnt,weil dieses Thema offensichtlich dreimal sobeliebtist wiejedes andere Thema auf dieser Site.Diese Websiteist speziell aufgrund solcher Fragenbeliebt und dahermachtes keinen Sinn,sie zu schließen.Ich denkenicht,dassman darüber diskutieren kann,wenn das Interesse der Community an solchen Themenfür Administratoren keinen Wert hat.@toscho - that is specifically why this was setup as a wiki and therefore this post is perfectly valid. The point I made in respect to page views was mentioned because this topic obviously is 3X as popular as any other topic on this site. This website is popular specifically due to questions like these and therefore it makes no sense to close it. I don't think one can debate this unless community interest in topics like these has no value towards admins.
- 0
- 2012-02-24
- NetConstructor.com
-
Ich werde hiereinen weiteren Kommentar hinzufügen,der aufeinigen Berechnungenbasiert,dieichgeradegemacht habe.Esgibt weniger als 790 registrierte Benutzer auf dieser Websitemit einer Bewertung von "1" odermehr.Angenommen,dieser Personenkreis repräsentiert diejenigen,dietatsächlich abstimmen und/oder zu dieser Websitebeitragen (und 790 sind unglaublichfair),dann repräsentieren 117 Personen,die diese Frage abgelehnt haben,14% + aller aktiven Benutzer,die dieses Themanützlichfanden.Stimmen Sie ab,um das Themaerneut zu öffnen.I will add one more comment on here based off some math I just did. There are less than 790 registered users on this website with a rating of "1" or more. Assuming this pool of individuals represents those who actually vote and/or contribute to this site (and 790 being incredibly fair) then 117 people who voted this question up represents 14%+ of all active users who found this topic useful. Vote to reopen the topic please.
- 0
- 2012-02-24
- NetConstructor.com
-
@ NetConstructor.com Besprechen Siees auf [Meta] (http://meta.wordpress.stackexchange.com/),wo die Leute Ihre Argumentebesser sehen können.:) :)@NetConstructor.com Discuss it on [Meta](http://meta.wordpress.stackexchange.com/) where people can see your arguments better. :)
- 6
- 2012-02-24
- fuxia
-
103 Antworten
- Stimmen
-
- 2010-09-10
Aktivieren Sie die Funktion "Versteckte Verwaltung",in der Alle Site-Einstellungen
angezeigt werdenGetestet am: WordPress 3.1 RC3
Dieser kleine Codemachtetwas ziemlich Cooles.Es wird Ihrem Einstellungsmenüeine zusätzliche Optionmit einem Link zu "Alle Einstellungen" hinzugefügt.Hier sehen Sieeine vollständige Liste aller Einstellungen,die Siein Ihrer Datenbankfür Ihre WordPress-Site vorgenommen haben.Derfolgende Codemacht diesen Linknurfüreinen Administrator sichtbar und verbirgtihnfür alle anderen Benutzer.
// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS function all_settings_link() { add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php'); } add_action('admin_menu', 'all_settings_link');
Enable Hidden Administration Feature displaying All Site Settings
Tested on: WordPress 3.1 RC3
This little piece of code does something pretty cool. It will add an additional option to your settings menu with a link to "all settings" which will show you a complete list of all the settings you have within your database related to your WordPress site. The code below will only made this link visible to an administrator user and hide it for all other users.
// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS function all_settings_link() { add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php'); } add_action('admin_menu', 'all_settings_link');
-
Fantastischfür die Entwicklung!Ich verwende die Optionstabelle häufig,um DB-Versionenfürmeine Plug-Ins zu speichern. Die Verwendung vonphpMyAdmin zum Zurücksetzen aufeine alte DB-Version zum Testeneines Upgrade-Skriptsist schmerzhaft. Diesmachtes ** so vieleinfacher **!!!Fantastic for development! I use the options table frequently to store DB versions for my plug-ins ... using phpMyAdmin to reset to an old DB version to test an upgrade script is a pain ... this will make it **so much easier**!!!
- 0
- 2010-09-15
- EAMann
-
Sie können dieselbe Optionsseite auch aufrufen (wenn Sie angemeldet sind),indem Sie auf Ihre Site/wp-admin/options.phpgehenYou can also get to the same options page (when logged in) by going to yoursite/wp-admin/options.php
- 3
- 2015-10-09
- j08691
-
- 2010-09-10
Ändern Sie das Login-Logo & amp; Bild-URL-Link
Getestet am: WordPress 3.0.1
Mit diesem Code können Sie das Logo der WordPress-Anmeldeseite sowie den href-Link und den Titeltext dieses Logoseinfach ändern.
add_filter( 'login_headerurl', 'namespace_login_headerurl' ); /** * Replaces the login header logo URL * * @param $url */ function namespace_login_headerurl( $url ) { $url = home_url( '/' ); return $url; } add_filter( 'login_headertitle', 'namespace_login_headertitle' ); /** * Replaces the login header logo title * * @param $title */ function namespace_login_headertitle( $title ) { $title = get_bloginfo( 'name' ); return $title; } add_action( 'login_head', 'namespace_login_style' ); /** * Replaces the login header logo */ function namespace_login_style() { echo '<style>.login h1 a { background-image: url( ' . get_template_directory_uri() . '/images/logo.png ) !important; }</style>'; }
BEARBEITEN: Wenn Sie das Site-Logo als Ersatzfür das Login-Logo verwendenmöchten,können Sie diese Informationen wiefolgt dynamisch abrufen (getestetin WP3.5 ). :
function namespace_login_style() { if( function_exists('get_custom_header') ){ $width = get_custom_header()->width; $height = get_custom_header()->height; } else { $width = HEADER_IMAGE_WIDTH; $height = HEADER_IMAGE_HEIGHT; } echo '<style>'.PHP_EOL; echo '.login h1 a {'.PHP_EOL; echo ' background-image: url( '; header_image(); echo ' ) !important; '.PHP_EOL; echo ' width: '.$width.'px !important;'.PHP_EOL; echo ' height: '.$height.'px !important;'.PHP_EOL; echo ' background-size: '.$width.'px '.$height.'px !important;'.PHP_EOL; echo '}'.PHP_EOL; echo '</style>'.PHP_EOL; }
Modify the Login Logo & Image URL Link
Tested on: WordPress 3.0.1
This code will allow you to easily modify the WordPress Login page Logo as well as the href link and title text of this logo.
add_filter( 'login_headerurl', 'namespace_login_headerurl' ); /** * Replaces the login header logo URL * * @param $url */ function namespace_login_headerurl( $url ) { $url = home_url( '/' ); return $url; } add_filter( 'login_headertitle', 'namespace_login_headertitle' ); /** * Replaces the login header logo title * * @param $title */ function namespace_login_headertitle( $title ) { $title = get_bloginfo( 'name' ); return $title; } add_action( 'login_head', 'namespace_login_style' ); /** * Replaces the login header logo */ function namespace_login_style() { echo '<style>.login h1 a { background-image: url( ' . get_template_directory_uri() . '/images/logo.png ) !important; }</style>'; }
EDIT: If you want to use the site logo to replace the login logo, you can use the following to dynamically pull that information (tested on WP3.5):
function namespace_login_style() { if( function_exists('get_custom_header') ){ $width = get_custom_header()->width; $height = get_custom_header()->height; } else { $width = HEADER_IMAGE_WIDTH; $height = HEADER_IMAGE_HEIGHT; } echo '<style>'.PHP_EOL; echo '.login h1 a {'.PHP_EOL; echo ' background-image: url( '; header_image(); echo ' ) !important; '.PHP_EOL; echo ' width: '.$width.'px !important;'.PHP_EOL; echo ' height: '.$height.'px !important;'.PHP_EOL; echo ' background-size: '.$width.'px '.$height.'px !important;'.PHP_EOL; echo '}'.PHP_EOL; echo '</style>'.PHP_EOL; }
-
- 2010-11-09
Fügen Siebenutzerdefinierte Beitragstypenin die Suchergebnisseein.
// MAKE CUSTOM POST TYPES SEARCHABLE function searchAll( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); } return $query; } add_filter( 'the_search_query', 'searchAll' );
Fügen Sie Ihrebenutzerdefinierten Beitragstypen standardmäßig zum Haupt-RSS-Feed Ihrer Website hinzu.
// ADD CUSTOM POST TYPES TO THE DEFAULT RSS FEED function custom_feed_request( $vars ) { if (isset($vars['feed']) && !isset($vars['post_type'])) $vars['post_type'] = array( 'post', 'site', 'plugin', 'theme', 'person' ); return $vars; } add_filter( 'request', 'custom_feed_request' );
Fügen Siebenutzerdefinierte Beitragstypenin "Sofort"ein. Admin-Dashboard-Widget
Dies umfasst Ihrebenutzerdefinierten Beitragstypen und die Anzahl der Beiträgefürjeden Typim & quot; "Jetzt". Dashboard-Widget.
// ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET function wph_right_now_content_table_end() { $args = array( 'public' => true , '_builtin' => false ); $output = 'object'; $operator = 'and'; $post_types = get_post_types( $args , $output , $operator ); foreach( $post_types as $post_type ) { $num_posts = wp_count_posts( $post_type->name ); $num = number_format_i18n( $num_posts->publish ); $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) ); if ( current_user_can( 'edit_posts' ) ) { $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>"; $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>"; } echo '<tr><td class="first num b b-' . $post_type->name . '">' . $num . '</td>'; echo '<td class="text t ' . $post_type->name . '">' . $text . '</td></tr>'; } $taxonomies = get_taxonomies( $args , $output , $operator ); foreach( $taxonomies as $taxonomy ) { $num_terms = wp_count_terms( $taxonomy->name ); $num = number_format_i18n( $num_terms ); $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms )); if ( current_user_can( 'manage_categories' ) ) { $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>"; $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>"; } echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>'; echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>'; } } add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
Include custom post types in the search results.
// MAKE CUSTOM POST TYPES SEARCHABLE function searchAll( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); } return $query; } add_filter( 'the_search_query', 'searchAll' );
Add your custom post types to your sites main RSS feed by default.
// ADD CUSTOM POST TYPES TO THE DEFAULT RSS FEED function custom_feed_request( $vars ) { if (isset($vars['feed']) && !isset($vars['post_type'])) $vars['post_type'] = array( 'post', 'site', 'plugin', 'theme', 'person' ); return $vars; } add_filter( 'request', 'custom_feed_request' );
Include custom post types in "Right Now" admin dashboard widget
This will include your custom post types and the post counts for each type in the "Right Now" dashboard widget.
// ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET function wph_right_now_content_table_end() { $args = array( 'public' => true , '_builtin' => false ); $output = 'object'; $operator = 'and'; $post_types = get_post_types( $args , $output , $operator ); foreach( $post_types as $post_type ) { $num_posts = wp_count_posts( $post_type->name ); $num = number_format_i18n( $num_posts->publish ); $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) ); if ( current_user_can( 'edit_posts' ) ) { $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>"; $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>"; } echo '<tr><td class="first num b b-' . $post_type->name . '">' . $num . '</td>'; echo '<td class="text t ' . $post_type->name . '">' . $text . '</td></tr>'; } $taxonomies = get_taxonomies( $args , $output , $operator ); foreach( $taxonomies as $taxonomy ) { $num_terms = wp_count_terms( $taxonomy->name ); $num = number_format_i18n( $num_terms ); $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms )); if ( current_user_can( 'manage_categories' ) ) { $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>"; $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>"; } echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>'; echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>'; } } add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
-
In Bezug auf den letzten Ausschnitt dieser Antwort.Diesisteine großartige Ergänzung,daich diesefürjeden Beitragstypmanuell hinzugefügt habe.Daseinzige Problem,dasich dabei habe,ist,dass die Datennach dem Standardeintrag "Kategorie" und "Tag" hinzugefügt werden.Könnten Sie Ihre Antwort aktualisieren,um die Standardkategorien "Kategorie" oder "Tag"nach unten zu verschieben oder zuentfernen,damit siemanuell hinzugefügt werden können?Regarding the last snippet to this answer. This is a great addition as I was adding these manually for each post type. The only issue I have with this is that it adds the data after the default "category" and "tag" entry. Could you update your answer to move the default "category" or "tag" ones down or remove them so that they can be added manually?
- 0
- 2011-02-22
- NetConstructor.com
-
@ NetConstructor.com Ichglaubenicht,dassich Ihre Anfrage verstehe.Wennich dastue,dann wäreesmeiner Meinungnachetwas schwieriger,undich habemomentannicht wirklich Zeit,um herauszufinden,wieesgeht.@NetConstructor.com I don't think I understand your request. If I do, then I think it would be a bit more of a difficult thing to do, and don't really have time right now to figure out how to do it.
- 0
- 2011-02-23
- jaredwilli
-
Fügen Siebenutzerdefinierte Beitragstypenin die Suchergebnisseein -ich denke,jetzt können Sie diesmit dem Parameter `exclude_from_search` von` register_post_type`tun ...Include custom post types in the search results - I guess, now you can do this with `exclude_from_search` param of `register_post_type`...
- 0
- 2013-12-16
- Krzysiek Dróżdż
-
- 2010-09-09
Entfernen Sie die Update-Benachrichtigungfür alle Benutzer außer ADMIN-Benutzer
Getestet am: WordPress 3.0.1
Dieser Code stellt sicher,dass keine anderen Benutzer als "admin" werden von WordPressbenachrichtigt,wenn Updates verfügbar sind.
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN global $user_login; get_currentuserinfo(); if ($user_login !== "admin") { // Change admin to the username that gets the updates add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }
Die Version wurde sogeändert,dassnur Aktualisierungsbenachrichtigungenfür Administratorbenutzer angezeigt werden (im Gegensatznurfür den Benutzer 'admin'):
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN global $user_login; get_currentuserinfo(); if (!current_user_can('update_plugins')) { // Checks to see if current user can update plugins add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }
Remove Update Notification for all users except ADMIN User
Tested on: WordPress 3.0.1
This code will ensures that no users other than "admin" are notified by WordPress when updates are available..
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN global $user_login; get_currentuserinfo(); if ($user_login !== "admin") { // Change admin to the username that gets the updates add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }
Changed version to only show update notification for admin users (as opposed to just the user 'admin'):
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN global $user_login; get_currentuserinfo(); if (!current_user_can('update_plugins')) { // Checks to see if current user can update plugins add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }
-
Dasist weit weniger alsideal.Esfunktioniertnur,wenn das Login des Administratorsimmernoch der Standard-Administ,was aus Sicherheitsgründennicht der Fall sein sollte.Stattdessen sollten Sienacheinerbestimmten Funktion suchen,bei der die Nachrichten angezeigt werden sollen.This is far less than ideal. It will only work if the admin's login is still the default 'admin', which it shoudln't be for security reasons. Instead you should check for a specific capability that you want people to have to see messages.
- 8
- 2010-09-11
- jerclarke
-
Das heißt,if (! current_user_can ('manage_options')) {... add_filter ...} - Entschuldigungfür den doppelten Kommentar,ich habe vergessen,dass durch Drücken der Eingabetaste Kommentaregesendet werden.)I.e. if (!current_user_can('manage_options')) {...add_filter...} -- Sorry about double comment, I forgot that hitting enter submits comments)
- 1
- 2010-09-11
- jerclarke
-
Deshalb habeich den Kommentar zum Code hinzugefügt,in dem Sie den Administrator-Benutzernamen ändern können.Wie würden Siees verbessern/umschreiben?Thats why I added the comment to the code where you can change the admin username. How would you improve/rewrite it?
- 0
- 2010-09-12
- NetConstructor.com
-
Derbeste Wegist,dasglobale $ user_login undget_currentuserinfo () zuentfernen und stattdessen current_user_canin Ihrerif-Klausel zu verwenden.Esistnur 1 Zeile statt 3 undesist der Standardweg.Sie können überprüfen,welche spezifischen Funktionenfür ACTin den Nachrichtenerforderlich sind. In diesem Fallgibt es 'update_core' und 'update_plugins'.The best way is to remove the global $user_login and get_currentuserinfo() and instead use current_user_can in your if clause. It's only 1 line instead of 3 and its the standard way. You can check for the specific capability that would be needed to ACT on the messages, in this case there's 'update_core' and 'update_plugins'.
- 0
- 2010-09-12
- jerclarke
-
also:if (! current_user_can ('update_plugins')) {/* NACHRICHTEN ENTFERNEN */}so: if (!current_user_can('update_plugins')) {/*REMOVE MESSAGES*/}
- 2
- 2010-09-12
- jerclarke
-
Also würde der vollständige Code wie aussehen?so the full code would look like what?
- 0
- 2010-09-13
- NetConstructor.com
-
@ Jeremy Clarke,wäre dieser Code dann die richtige Vorgehensweise?Aber wenn Sienureinem bestimmten Benutzernamenerlaubenmöchten,die Benachrichtigungen zuerhalten,wäre der obige Code derbeste Weg? if (! current_user_can ('update_plugins')) { add_action ('init',create_function ('$ a',"remove_action ('init','wp_version_check');"),2); add_filter ('pre_option_update_core',create_function ('$ a',"returnnull;")); }}@Jeremy Clarke so would this code then be the correct way of doing things? But, if you just wanted to allow a specific username to get the notices would the code above be the best way? if (!current_user_can('update_plugins')) { add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" )); }
- 0
- 2010-09-17
- NetConstructor.com
-
Wenn Sienacheinem bestimmten Benutzernamen suchenmöchten,ist Ihr Codein der ursprünglichen Antwort vermutlich akzeptabel,obwohlesmöglicherweiseeinen etwaseffektiveren Weggibt.Der vollständige Code,dermeine Lösung verwendet,würde so aussehen,wie Sieihnin Ihrem letzten Kommentar haben.Esist dasgleiche wie Ihre Antwort,jedochmit der Prüfung current_user_can () anstelle von $ user_login!=='admin'.If you wanted to check for a specific user name I suppose your code in the original answer is acceptable, though there may be a slightly more effective way. The full code using my solution would look like what you have in your last comment. It's the same as your answer but with the current_user_can() check instead of the $user_login !== 'admin'.
- 0
- 2010-09-22
- jerclarke
-
Ich habe die Antwortbearbeitet und die Version hinzugefügt,die current_user_can verwendet ('update_plugins').I edited the answer and added the version that uses current_user_can('update_plugins')
- 0
- 2010-09-27
- Travis Northcutt
-
Diese Logikmussin den KerngehenThis logic must go inside the core
- 0
- 2010-12-27
- Atif Mohammed Ameenuddin
-
Ich habegerade die Codes ausprobiert.Aberichbekommeeine Fehlerseite,wennich die Codes verwende.Gleiches Problemmit beiden CodesI just tried the codes. But I am getting some error page if I use the codes. Same problem with both the codes
- 0
- 2011-06-29
- user391
-
Ich denke,dieses Snippet hatim Laufe der Jahre an Relevanz verloren.In WordPressist der Administrator dereinzige,der Update-Benachrichtigungen sieht.I think this snippet lost it's relevance over the years. In actual WordPress the administrator is the only one who is seeing update notifications.
- 0
- 2014-08-28
- netblognet
-
- 2010-09-16
Laden vonjQuery aus dem Google CDN
Getestet auf: WordPress 3.0.1
// Even more smart jQuery inclusion :) add_action( 'init', 'jquery_register' ); // Register from Google and for footer function jquery_register() { if ( !is_admin() ) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', ( 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ), false, null, true ); wp_enqueue_script( 'jquery' ); } }
Entfernen Sie die WordPress-Versionsinformationenfür die Sicherheit
Getestet auf: WordPress 3.0.1
// Remove version info from head and feeds function complete_version_removal() { return ''; } add_filter('the_generator', 'complete_version_removal');
Spam hinzufügen & amp; Löschen Sie Links zu Kommentarenim Frontend
Getestet auf: WordPress 3.0.1
Dieserleichtert die Verwaltung von Kommentarenim Frontend durch Hinzufügen von Spam und Löschen von Links. **
// Spam & delete links for all versions of WordPress function delete_comment_link($id) { if (current_user_can('edit_post')) { echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> '; echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>'; } }
Verzögern Sie die öffentliche Veröffentlichungim RSS-Feed
Getestet auf: WordPress 3.0.1
Schließlichmöchteich das Postenin meinen RSS-Feeds um 10-15 Minuten verzögern,daichin meinem Textimmermindestensein paar Fehlerfinde. Andere Verwendungszwecke sindfür den Fall,dass Inhaltefüreinen Tag odereine Wocheexklusivfür Ihre Website sein sollen,bevor sie an Ihre RSS-Readergesendet werden.
// Delay feed update function publish_later_on_feed($where) { global $wpdb; if (is_feed()) { // Timestamp in WordPress format $now = gmdate('Y-m-d H:i:s'); // Value for wait; + device $wait = '10'; // integer // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff $device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR // Add SQL syntax to default $where $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; } return $where; } add_filter('posts_where', 'publish_later_on_feed');
Loading jQuery from the Google CDN
Tested on: WordPress 3.0.1
// Even more smart jQuery inclusion :) add_action( 'init', 'jquery_register' ); // Register from Google and for footer function jquery_register() { if ( !is_admin() ) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', ( 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ), false, null, true ); wp_enqueue_script( 'jquery' ); } }
Remove the WordPress Version Info for Security
Tested on: WordPress 3.0.1
// Remove version info from head and feeds function complete_version_removal() { return ''; } add_filter('the_generator', 'complete_version_removal');
Add Spam & Delete Links to Comments on Front End
Tested on: WordPress 3.0.1
This makes it way easier to manage comments from the front end by adding spam and delete links.**
// Spam & delete links for all versions of WordPress function delete_comment_link($id) { if (current_user_can('edit_post')) { echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> '; echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>'; } }
Delay the public posting to RSS Feed
Tested on: WordPress 3.0.1
Finally, I like to delay posting to my RSS feeds for 10-15 minutes because I always find at least a couple errors in my text. Other uses are in case you want content to be exclusive to your site for a day or a week before pushing it out to your RSS readers.
// Delay feed update function publish_later_on_feed($where) { global $wpdb; if (is_feed()) { // Timestamp in WordPress format $now = gmdate('Y-m-d H:i:s'); // Value for wait; + device $wait = '10'; // integer // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff $device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR // Add SQL syntax to default $where $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; } return $where; } add_filter('posts_where', 'publish_later_on_feed');
-
Quellein meinem Beitrag: http://wpengineer.com/320/publish-the-feed-later/mit weiteren Informationensource on my post: http://wpengineer.com/320/publish-the-feed-later/ with more informations
- 0
- 2010-09-17
- bueltge
-
Sie können aucheinfach den Generatorfilterentfernen: `remove_action ('wp_head','wp_generator');`You can also just remove the generator filter: `remove_action('wp_head', 'wp_generator');`
- 1
- 2010-09-18
- Gipetto
-
Warum verwenden wir Google CDNnicht auchfür Administratoren?Ich habeesnicht verstandenWhy dont we use google cdn for admin too? I didnt get it
- 0
- 2010-11-05
- Ünsal Korkmaz
-
@Derek Perkins - Können Siejedem dieser Codefragmenteeine andere Antwortgeben,damit überjedeseinzeln abgestimmt werden kann?@Derek Perkins - Can you make each of these code snippets a different answer so they can each be voted on separately?
- 0
- 2010-11-06
- MikeSchinkel
-
http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js läuftnachnureiner Stunde ab.** Verwenden Sieimmer ** die Vollversionsinformationen wie http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js - dienacheinem Jahr ablaufen.http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js expires after just one hour. **Always** use the full version information like http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js – that expires after one year.
- 25
- 2010-11-10
- fuxia
-
Können Siebitte jeden dieser Wiki-Einträgein dennächsten Wochenin separate Einträge aufteilen?Ich wollteesfür Sietun,aberich wolltenicht den Eindruckerwecken,dassich versuche,Punktefür Informationen zu sammeln,die Siegeteilt haben.Can you please split each of these wiki entries up into separate entries within the next few weeks. I wanted to do it for you but I did not want to make it seem like I am trying to take points for information you shared.
- 0
- 2011-01-26
- NetConstructor.com
-
Der Code "WordPress-Versionsinfofür Sicherheitentfernen"trägtnicht dazubei,die Sicherheit Ihrer Website zuerhöhen.Es stopptnichteinmal die Veröffentlichung der WP-Version,die auf Ihrer Site verwendet wird.The "Remove the WordPress Version Info for Security" code doesn't actually do anything to increase the security of your site. It doesn't even stop exposure of the WP version being used on your site.
- 5
- 2011-02-11
- Joseph Scott
-
Nicht wahr Joseph,wenn Ihre WordPress-Version verfügbarist,können die Leute sehen,ob Sieeine ältere Version verwenden,wodurch Ihre Schwachstellen aufgedeckt werden.Esistimmereine gute Entscheidung,dies aus allen WordPress-Installationen zuentfernen.Persönlich weißichnichteinmal,warum siees überhaupt dort abgelegt haben,daes sich umein Sicherheitsproblem handelt.Not true Joseph, if your WordPress version is exposed then people can see if you are running an older version, thus exposing your vulnerabilities. It is always a good decision to remove that from all WordPress installs. Personally, I don't even know why they put it there in the first place as it IS a security issue.
- 1
- 2014-05-12
- Jeremy
-
- 2010-09-11
Legen Sieeine maximale Anzahl von Nachrevisionenfest,umein Aufblähen der Datenbank zu vermeiden.
Getestet am: WordPress 3.0.1
Der Standardwertist unendlich. Dadurch werdennur die letztenfünf Änderungengespeichert:
/** * Set the post revisions unless the constant was set in wp-config.php */ if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 5);
Für das,wases wertist,gibt eseine Mengegroßartiger Ideenfür CONSTANTS,die auf der Codex-Seite Bearbeiten von wp-config.php .
Set a maximum number of post revisions to avoid DB bloat.
Tested on: WordPress 3.0.1
The default is infinite, and this will set it to only remember the last five edits:
/** * Set the post revisions unless the constant was set in wp-config.php */ if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 5);
For what it's worth, there are a ton of great ideas for CONSTANTS that can be set on the Codex page Editing wp-config.php.
-
Kann diespro Posttypfestgelegt werden?Can this be set on a per post type basis?
- 0
- 2010-09-12
- NetConstructor.com
-
Angesichts der Verwendungin wp_save_post_revision () scheintes keine Möglichkeit zugeben,anhand von Beitragstypen zu unterscheiden.Esgibt keinen Filter oderirgendetwas auf dem Wert,obwohles wahrscheinlicheinen geben sollte.Looking at its usage in wp_save_post_revision() there doesn't seem to be a way to distinguish based on post types. There's no filter or anything on the value, though there probably should be.
- 0
- 2010-09-12
- jerclarke
-
danke Jeremy - Wenn Sie wissen,wie dasgeht,posten Sieesbitte hier.thanks Jeremy - To anyone else, if you know how to do this please post it here.
- 0
- 2010-09-14
- NetConstructor.com
-
Ichpersönlichbevorzuge 10. Ich weiß,dasses doppeltist,aber wennicheine Revisionbrauche,istesimmer älter als 5personally I prefer 10. I know it's double but always when I need a revision it's always older then 5
- 1
- 2012-09-04
- janw
-
- 2011-12-04
Schärfen Sie vergrößerte Bilder (nur JPEG)
Diese Funktion schärft die Größe von JPEG-Bildern. Ein Beispielfüreinen Unterschied:
function ajx_sharpen_resized_files( $resized_file ) { $image = wp_load_image( $resized_file ); if ( !is_resource( $image ) ) return new WP_Error( 'error_loading_image', $image, $file ); $size = @getimagesize( $resized_file ); if ( !$size ) return new WP_Error('invalid_image', __('Could not read image size'), $file); list($orig_w, $orig_h, $orig_type) = $size; switch ( $orig_type ) { case IMAGETYPE_JPEG: $matrix = array( array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1), ); $divisor = array_sum(array_map('array_sum', $matrix)); $offset = 0; imageconvolution($image, $matrix, $divisor, $offset); imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 90, 'edit_image' )); break; case IMAGETYPE_PNG: return $resized_file; case IMAGETYPE_GIF: return $resized_file; } return $resized_file; } add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files', 900);
Sharpen Resized Images (only JPEG)
This function sharpens resized JPEG images. An example of a difference:
function ajx_sharpen_resized_files( $resized_file ) { $image = wp_load_image( $resized_file ); if ( !is_resource( $image ) ) return new WP_Error( 'error_loading_image', $image, $file ); $size = @getimagesize( $resized_file ); if ( !$size ) return new WP_Error('invalid_image', __('Could not read image size'), $file); list($orig_w, $orig_h, $orig_type) = $size; switch ( $orig_type ) { case IMAGETYPE_JPEG: $matrix = array( array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1), ); $divisor = array_sum(array_map('array_sum', $matrix)); $offset = 0; imageconvolution($image, $matrix, $divisor, $offset); imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 90, 'edit_image' )); break; case IMAGETYPE_PNG: return $resized_file; case IMAGETYPE_GIF: return $resized_file; } return $resized_file; } add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files', 900);
-
viel,vielbessere JPEGs,vielen Dank!getestetin 3.4-alphamuch much better jpegs, thanks a bunch! tested in 3.4-alpha
- 0
- 2012-04-02
- brasofilo
-
Wennihr das als Plugin wollt: http://wordpress.org/extend/plugins/sharpen-resized-images/if u guys want this as plugin: http://wordpress.org/extend/plugins/sharpen-resized-images/
- 2
- 2012-04-03
- Ünsal Korkmaz
-
Wohingeht diese Funktion?where does this function go?
- 0
- 2019-03-18
- StevieD
-
@StevieD - Wie der Titel schon sagt,befindetes sichin Ihrer Vorlagein functions.php.Ich wäre allerdings vorsichtig,diese Funktionistfast 8 Jahre alt.@StevieD - as the title suggests, it goes inside functions.php, in your template. I would be careful though, this function is almost 8 years old.
- 0
- 2019-07-25
- timofey.com
-
- 2010-09-09
Standard-WordPress-Meta-Boxenentfernen
Getestet am: WordPress 3.0.1
Mit diesem Code können Siebestimmte Meta-Boxenentfernen,die WordPress standardmäßig zu den Standardbildschirmen "Beitrag hinzufügen/bearbeiten" und "Seite hinzufügen/bearbeiten" hinzufügt.
// REMOVE META BOXES FROM DEFAULT POSTS SCREEN function remove_default_post_screen_metaboxes() { remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Metabox remove_meta_box( 'trackbacksdiv','post','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox remove_meta_box( 'authordiv','post','normal' ); // Author Metabox } add_action('admin_menu', 'remove_default_post_screen_metaboxes'); // REMOVE META BOXES FROM DEFAULT PAGES SCREEN function remove_default_page_screen_metaboxes() { remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox remove_meta_box( 'authordiv','page','normal' ); // Author Metabox } add_action('admin_menu', 'remove_default_page_screen_metaboxes');
Remove Default WordPress Meta Boxes
Tested on: WordPress 3.0.1
This code will allow you to remove specific Meta Boxes which WordPress adds by default to the default Add/Edit Post and Add/Edit Page screens.
// REMOVE META BOXES FROM DEFAULT POSTS SCREEN function remove_default_post_screen_metaboxes() { remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Metabox remove_meta_box( 'trackbacksdiv','post','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox remove_meta_box( 'authordiv','post','normal' ); // Author Metabox } add_action('admin_menu', 'remove_default_post_screen_metaboxes'); // REMOVE META BOXES FROM DEFAULT PAGES SCREEN function remove_default_page_screen_metaboxes() { remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox remove_meta_box( 'authordiv','page','normal' ); // Author Metabox } add_action('admin_menu', 'remove_default_page_screen_metaboxes');
-
Laut diesem http://wordpress.stackexchange.com/questions/34030/cant-change-permalink-url-after-hitting-ok-and-update/37779#37779 würdeich den Slugdivnicht auf diese Weise verstecken,sondern verwendendiese https://gist.github.com/1863830 stattdessenAccording to this http://wordpress.stackexchange.com/questions/34030/cant-change-permalink-url-after-hitting-ok-and-update/37779#37779 I wouldn't hide the slugdiv this way, but use this https://gist.github.com/1863830 instead
-
@CorvanNoorloos Dein Github-Linkist defekt.@CorvanNoorloos Your github link is broken.
- 0
- 2017-02-26
- user7003859
-
- 2010-09-15
& quot; Wordpress & quot;entfernenzu & quot; WordPress & quot;Filter
Getestet am: WordPress 3.0.1
Mit WordPress Version 3.0 wurdeein Filter hinzugefügt,der automatisch alle Instanzen von "Wordpress" konvertiert.(kein Großbuchstabe P) zu "WordPress"(miteinem Großbuchstaben P)in Post-Inhalten,Post-Titeln und Kommentartext.Einige Leute sehen dies als aufdringlich an,aberichmuss WordPress von Zeit zu Zeitfalschinterpretieren undfand den Filteretwasnervig.
// Remove annoying P filter if(function_exists('capital_P_dangit')) { foreach ( array( 'the_content', 'the_title' ) as $filter ) remove_filter( $filter, 'capital_P_dangit', 11 ); remove_filter('comment_text', 'capital_P_dangit', 31 ); }
Remove "Wordpress" to "WordPress" filter
Tested on: WordPress 3.0.1
There was a filter added with WordPress version 3.0 that automatically converts all instances of "Wordpress" (no capital P) to "WordPress" (with a capital P) in post content, post titles, and comment text. Some people see this as intrusive, but I just have a need to mis-case WordPress from time to time and found the filter somewhat annoying.
// Remove annoying P filter if(function_exists('capital_P_dangit')) { foreach ( array( 'the_content', 'the_title' ) as $filter ) remove_filter( $filter, 'capital_P_dangit', 11 ); remove_filter('comment_text', 'capital_P_dangit', 31 ); }
-
toller kleiner Fund.Eines dieser Dinge,dasnureinen weiteren Codeentfernt,dernichtbenötigt wirdgreat little find. One of those things which just removes another piece of code that is not needed
- 0
- 2010-09-17
- NetConstructor.com
-
In WordPress 3.0.1 wird [dieser Filtermit Priorität 11 hinzugefügt] (http://core.trac.wordpress.org/changeset/15378/branches/3.0/wp-includes/default-filters.php)um `11` als dritten Parameter hinzuzufügen,umes zuentfernen.In WordPress 3.0.1, [this filter is added with priority 11](http://core.trac.wordpress.org/changeset/15378/branches/3.0/wp-includes/default-filters.php), so you need to add `11` as the third parameter to remove it.
- 5
- 2010-11-05
- Jan Fabry
-
- 2010-10-21
Passen Sie das Dashboard an
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets'); function my_custom_dashboard_widgets() { global $wp_meta_boxes;
Entfernen Sie diese Dashboard-Widgets ...
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
Fügen Sieein benutzerdefiniertes Widgetmit dem Namen "Hilfe und Support" hinzu.
wp_add_dashboard_widget('custom_help_widget', 'Help and Support', 'custom_dashboard_help'); }
Diesist der Inhaltfür Ihrbenutzerdefiniertes Widget
function custom_dashboard_help() { echo '<p>Lorum ipsum delor sit amet et nunc</p>'; }
Customize the Dashboard
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets'); function my_custom_dashboard_widgets() { global $wp_meta_boxes;
Remove these dashboard widgets...
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
Add a custom widget called 'Help and Support'
wp_add_dashboard_widget('custom_help_widget', 'Help and Support', 'custom_dashboard_help'); }
This is the content for your custom widget
function custom_dashboard_help() { echo '<p>Lorum ipsum delor sit amet et nunc</p>'; }
-
- 2010-11-16
Benutzerdefinierte Benutzerprofilfelder hinzufügen
Fügen Sie denfolgenden Codein Ihre Dateifunctions.phpein,umbenutzerdefinierte Benutzerprofilfelder hinzuzufügen. Bearbeiten oderfügen Sie Liniennach Belieben hinzu.
Denken Sie daran,die Zeilenicht zuentfernen: return $ contactmethods; Andernfallsfunktioniert diesnicht.
// CUSTOM USER PROFILE FIELDS function my_custom_userfields( $contactmethods ) { // ADD CONTACT CUSTOM FIELDS $contactmethods['contact_phone_office'] = 'Office Phone'; $contactmethods['contact_phone_mobile'] = 'Mobile Phone'; $contactmethods['contact_office_fax'] = 'Office Fax'; // ADD ADDRESS CUSTOM FIELDS $contactmethods['address_line_1'] = 'Address Line 1'; $contactmethods['address_line_2'] = 'Address Line 2 (optional)'; $contactmethods['address_city'] = 'City'; $contactmethods['address_state'] = 'State'; $contactmethods['address_zipcode'] = 'Zipcode'; return $contactmethods; } add_filter('user_contactmethods','my_custom_userfields',10,1);
Umbenutzerdefinierte Felder anzuzeigen,können Sieeine derbeiden unten aufgeführten Methoden verwenden.
Option 1:
the_author_meta('facebook', $current_author->ID)
Option 2:
<?php $current_author = get_userdata(get_query_var('author')); ?> <p><a href="<?php echo esc_url($current_author->contact_phone_office);?>" title="office_phone"> Office Phone</a></p>
Add Custom User Profile Fields
Place the code below into your functions.php file to add custom user profile fields. Edit or add lines as you see fit.
Remember not to remove the line: return $contactmethods; otherwise this won't work.
// CUSTOM USER PROFILE FIELDS function my_custom_userfields( $contactmethods ) { // ADD CONTACT CUSTOM FIELDS $contactmethods['contact_phone_office'] = 'Office Phone'; $contactmethods['contact_phone_mobile'] = 'Mobile Phone'; $contactmethods['contact_office_fax'] = 'Office Fax'; // ADD ADDRESS CUSTOM FIELDS $contactmethods['address_line_1'] = 'Address Line 1'; $contactmethods['address_line_2'] = 'Address Line 2 (optional)'; $contactmethods['address_city'] = 'City'; $contactmethods['address_state'] = 'State'; $contactmethods['address_zipcode'] = 'Zipcode'; return $contactmethods; } add_filter('user_contactmethods','my_custom_userfields',10,1);
To display custom fields you can use one of the two methods listed below.
Option 1:
the_author_meta('facebook', $current_author->ID)
Option 2:
<?php $current_author = get_userdata(get_query_var('author')); ?> <p><a href="<?php echo esc_url($current_author->contact_phone_office);?>" title="office_phone"> Office Phone</a></p>
-
- 2010-09-09
Passen Sie die Reihenfolge des Administrationsmenüs an
Getestet auf: WordPress 3.0.1
Mit diesem Code können Sie die Reihenfolge der Elementeim Verwaltungsmenüneu organisieren. Alles,was Sietunmüssen,ist aufeinen vorhandenen Linkim Administrationsmenü zu klicken und alles vor der/wp-admin/URL zu kopieren. Diefolgende Reihenfolgegibt die Reihenfolge an,die dasneue Verwaltungsmenü haben wird.
// CUSTOMIZE ADMIN MENU ORDER function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // This represents the dashboard link 'edit.php?post_type=events', // This is a custom post type menu 'edit.php?post_type=news', 'edit.php?post_type=articles', 'edit.php?post_type=faqs', 'edit.php?post_type=mentors', 'edit.php?post_type=testimonials', 'edit.php?post_type=services', 'edit.php?post_type=page', // This is the default page menu 'edit.php', // This is the default POST admin menu ); } add_filter('custom_menu_order', 'custom_menu_order'); add_filter('menu_order', 'custom_menu_order');
Customize the order of the administration menu
Tested on: WordPress 3.0.1
This code will allow you to reorganize the order of elements in the administration menu. All that you need to do is click on an existing link in the administration menu and copy everything before the /wp-admin/ URL. The order below represents the order the new administration menu will have.
// CUSTOMIZE ADMIN MENU ORDER function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // This represents the dashboard link 'edit.php?post_type=events', // This is a custom post type menu 'edit.php?post_type=news', 'edit.php?post_type=articles', 'edit.php?post_type=faqs', 'edit.php?post_type=mentors', 'edit.php?post_type=testimonials', 'edit.php?post_type=services', 'edit.php?post_type=page', // This is the default page menu 'edit.php', // This is the default POST admin menu ); } add_filter('custom_menu_order', 'custom_menu_order'); add_filter('menu_order', 'custom_menu_order');
-
Gibtes wirklicheinen Kernfilternamens "custom_menu_order"?Ich konnte keinenfinden ...Is there really a core filter named `custom_menu_order`? I couldn't find one...
- 0
- 2011-03-01
- kaiser
-
@kaiser hier dokumentiert http://codex.wordpress.org/Plugin_API/Filter_Reference/custom_menu_order@kaiser documented here http://codex.wordpress.org/Plugin_API/Filter_Reference/custom_menu_order
- 4
- 2012-08-18
- Manny Fleurmond
-
- 2010-09-12
Funktion zum Ändern der Länge von Auszug
Getestet am: Wordpress 3.0.1
Standardmäßig sind alle Auszüge auf 55 Wörterbegrenzt.Mit demfolgenden Code können Sie diese Standardeinstellungen überschreiben:
function new_excerpt_length($length) { return 100; } add_filter('excerpt_length', 'new_excerpt_length');
In diesem Beispiel wird die Auszugslänge auf 100 Wörtergeändert. Sie können siejedochmit derselben Methodein einenbeliebigen Wert ändern.
Function to change the length of Exerpt
Tested on: Wordpress 3.0.1
By default all excerpts are capped at 55 words. Utilizing the code below you can override this default settings:
function new_excerpt_length($length) { return 100; } add_filter('excerpt_length', 'new_excerpt_length');
This example changes the excerpt length to 100 words, but you can use the same method to change it to any value.
-
@ user402 ... wird diese Kappe durch Wörter oder Zeichen?Könntest duposten,wiemanbeidesmacht?@user402... does this cap by words or characters? Could you post how to do both?
- 0
- 2010-09-12
- NetConstructor.com
-
*@NetConstructor.com* Diese Funktion (und der Hook "excerpt_length") [capby words] (http://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_length).*@NetConstructor.com* This function (and the `excerpt_length` hook) [cap by words](http://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_length).
- 3
- 2010-09-15
- EAMann
-
Heh.Ich habe diesen Filter zum Kern hinzugefügt.:) :)Heh. I got that filter added to core. :)
- 0
- 2011-03-08
- Dougal Campbell
-
- 2010-12-28
Thumbnailsin Liste "Beiträge/Seiten verwalten" hinzufügen
Sie können dies zu Ihren Funktionen hinzufügen,umin der Liste "Beitrag verwalten undbearbeiten"eine neue Spaltemit der Vorschau der Miniaturansichten anzuzeigen.
/****** Add Thumbnails in Manage Posts/Pages List ******/ if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) { // for post and page add_theme_support('post-thumbnails', array( 'post', 'page' ) ); function AddThumbColumn($cols) { $cols['thumbnail'] = __('Thumbnail'); return $cols; } function AddThumbValue($column_name, $post_id) { $width = (int) 35; $height = (int) 35; if ( 'thumbnail' == $column_name ) { // thumbnail of WP 2.9 $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true ); // image from gallery $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') ); if ($thumbnail_id) $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true ); elseif ($attachments) { foreach ( $attachments as $attachment_id => $attachment ) { $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true ); } } if ( isset($thumb) && $thumb ) { echo $thumb; } else { echo __('None'); } } } // for posts add_filter( 'manage_posts_columns', 'AddThumbColumn' ); add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 ); // for pages add_filter( 'manage_pages_columns', 'AddThumbColumn' ); add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 ); }
Add Thumbnails in Manage Posts/Pages List
You can add this to your functions to display to the Manage/Edit Post and Pages List a new column with the thumbnail preview.
/****** Add Thumbnails in Manage Posts/Pages List ******/ if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) { // for post and page add_theme_support('post-thumbnails', array( 'post', 'page' ) ); function AddThumbColumn($cols) { $cols['thumbnail'] = __('Thumbnail'); return $cols; } function AddThumbValue($column_name, $post_id) { $width = (int) 35; $height = (int) 35; if ( 'thumbnail' == $column_name ) { // thumbnail of WP 2.9 $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true ); // image from gallery $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') ); if ($thumbnail_id) $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true ); elseif ($attachments) { foreach ( $attachments as $attachment_id => $attachment ) { $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true ); } } if ( isset($thumb) && $thumb ) { echo $thumb; } else { echo __('None'); } } } // for posts add_filter( 'manage_posts_columns', 'AddThumbColumn' ); add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 ); // for pages add_filter( 'manage_pages_columns', 'AddThumbColumn' ); add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 ); }
-
Wie verschiebeich die Spalteganznach links?How to move the column to the far left?
- 0
- 2013-10-08
- Rich
-
- 2010-09-15
Entfernen Sie Pingsin Ihremeigenen Blog
Getestet am: WordPress 3.0.1
// Remove pings to self function no_self_ping( &$links ) { $home = get_option( 'home' ); foreach ( $links as $l => $link ) if ( 0 === strpos( $link, $home ) ) unset($links[$l]); } add_action( 'pre_ping', 'no_self_ping' );
Remove pings to your own blog
Tested on: WordPress 3.0.1
// Remove pings to self function no_self_ping( &$links ) { $home = get_option( 'home' ); foreach ( $links as $l => $link ) if ( 0 === strpos( $link, $home ) ) unset($links[$l]); } add_action( 'pre_ping', 'no_self_ping' );
-
Wie oft und wannpingt sich WordPress selbst an?how often and when does wordpress ping itself?
- 0
- 2010-09-17
- NetConstructor.com
-
Ich habe dieses Problemtatsächlich ziemlich oft.Wennich aufeinen internen Link zueinem anderen Beitragin meinem WP-Blog verweise,erhalteich vonmir selbsteinen Trackback oder Pingback (weißnichtmehr,welcher).Esistnervig.I actually have that issue quite often. If I reference an internal link to another post on my WP blog, I get a trackback or pingback (don't remember which) from myself. It's annoying.
- 0
- 2010-12-18
- Sahas Katta
-
Hiergilt dasgleiche.Ich habeeinen News-/Magazin-Blog und verlinke ziemlich oft zu anderen Artikeln.Same here. I have a news / magazine blog and link to other articles quite often.
- 0
- 2011-02-13
- Steven
-
- 2010-12-23
Aktivieren Sie die GZIP-Ausgabekomprimierung
Normalerweise sollte der Server soeingerichtet sein,dass dies automatischerfolgt,aber vielegemeinsamgenutzte Hoststun diesnicht (wahrscheinlich,um die Bandbreitennutzung des Clients zuerhöhen).
if(extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler")) add_action('wp', create_function('', '@ob_end_clean();@ini_set("zlib.output_compression", 1);'));
Enable GZIP output compression
Normally the server should be set up to do this automatically, but a lot of shared hosts don’t do this (probably to increase client bandwidth usage).
if(extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler")) add_action('wp', create_function('', '@ob_end_clean();@ini_set("zlib.output_compression", 1);'));
-
- 2010-09-15
DB-Abfragen,Zeitaufwand und Speicherverbrauch anzeigen
Getestet am: WordPress 3.0.1
function performance( $visible = false ) { $stat = sprintf( '%d queries in %.3f seconds, using %.2fMB memory', get_num_queries(), timer_stop( 0, 3 ), memory_get_peak_usage() / 1024 / 1024 ); echo $visible ? $stat : "<!-- {$stat} -->" ; }
Dann dieser Code unter dem obigen Code,der den obigen Code automatischin die Fußzeile Ihrer öffentlichen Websiteeinfügt (stellen Sie sicher,dass Ihr Thema
wp_footer
aufruft):add_action( 'wp_footer', 'performance', 20 );
Es kannmehrmals aufgerufen werden.
Display DB Queries, Time Spent and Memory Consumption
Tested on: WordPress 3.0.1
function performance( $visible = false ) { $stat = sprintf( '%d queries in %.3f seconds, using %.2fMB memory', get_num_queries(), timer_stop( 0, 3 ), memory_get_peak_usage() / 1024 / 1024 ); echo $visible ? $stat : "<!-- {$stat} -->" ; }
Then this code below the code above which will automatically insert the code above into the footer of your public website (make sure your theme is calling
wp_footer
):add_action( 'wp_footer', 'performance', 20 );
It can be called multiple times.
-
fürphp <5.2benutze `memory_get_usage ()`for php < 5.2 use `memory_get_usage()`
- 0
- 2011-01-23
- onetrickpony
-
- 2010-11-14
Aufheben der Registrierung von WordPress-Standard-Widgets
Getestet am: WordPress 3.0.1
// Unregister all default WordPress Widgets function unregister_default_wp_widgets() { unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); unregister_widget('WP_Widget_Search'); unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Recent_Posts'); unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_RSS'); unregister_widget('WP_Widget_Tag_Cloud'); } add_action('widgets_init', 'unregister_default_wp_widgets', 1);
Unregister WordPress Default Widgets
Tested on: WordPress 3.0.1
// Unregister all default WordPress Widgets function unregister_default_wp_widgets() { unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); unregister_widget('WP_Widget_Search'); unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Recent_Posts'); unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_RSS'); unregister_widget('WP_Widget_Tag_Cloud'); } add_action('widgets_init', 'unregister_default_wp_widgets', 1);
-
Ich habeesin Version 3.1.4 verwendet.Aber die Widgets sindimmernoch da.Hatjemandeine Idee?I have used it on Version 3.1.4 . But the widgets are still there. Does any one have idea?
- 0
- 2011-07-01
- user391
-
Funktioniertimmernochmit WP 4.5 :)Still works on WP 4.5 :)
- 0
- 2016-04-19
- Tim Malone
-
- 2010-09-10
Daserste Bild automatisch aus dem Post-Inhaltextrahieren
Getestet am: WordPress 3.0.1
Mit diesem Code wird automatisch daserste Bildextrahiert,daseinem Beitrag zugeordnetist,und Sie könnenes anzeigen/verwenden,indem Sie die FunktiongetImage aufrufen.
// AUTOMATICALLY EXTRACT THE FIRST IMAGE FROM THE POST function getImage($num) { global $more; $more = 1; $link = get_permalink(); $content = get_the_content(); $count = substr_count($content, '<img'); $start = 0; for($i=1;$i<=$count;$i++) { $imgBeg = strpos($content, '<img', $start); $post = substr($content, $imgBeg); $imgEnd = strpos($post, '>'); $postOutput = substr($post, 0, $imgEnd+1); $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);; $image[$i] = $postOutput; $start=$imgEnd+1; } if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; } $more = 0; }
Auto Extract the First Image from the Post Content
Tested on: WordPress 3.0.1
This code will automatically extract the first image associated with a post and allow you to display/use it by calling the getImage function.
// AUTOMATICALLY EXTRACT THE FIRST IMAGE FROM THE POST function getImage($num) { global $more; $more = 1; $link = get_permalink(); $content = get_the_content(); $count = substr_count($content, '<img'); $start = 0; for($i=1;$i<=$count;$i++) { $imgBeg = strpos($content, '<img', $start); $post = substr($content, $imgBeg); $imgEnd = strpos($post, '>'); $postOutput = substr($post, 0, $imgEnd+1); $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);; $image[$i] = $postOutput; $start=$imgEnd+1; } if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; } $more = 0; }
-
Schön,aberget_the_imagemacht auch hiereinen sehrguten Job.http://wordpress.org/extend/plugins/get-the-image/Nice, but get_the_image does a very good job with this as well. http://wordpress.org/extend/plugins/get-the-image/
- 6
- 2010-09-15
- artlung
-
richtig,aber diesesfunktioniert anders undbehebt verschiedene Probleme,dieget_the_imagenichtberücksichtigtcorrect but this one works differently and fixes various issues which get_the_image does not take into account
- 0
- 2010-09-30
- NetConstructor.com
-
Wasmachtes anders als das Skriptget_the_image?What does it do differently than the get_the_image script?
- 3
- 2010-12-05
- matt
-
@matt - In WordPressgibt es verschiedene Möglichkeiten,wie Bilder zu Posts hinzugefügt werden können,undich denke,dasget_the_image-Skriptbetrachtetnureine davon.Hiermit wird überprüft,obein Bild vorhandenist,und dieses wird zuerst verwendet,sofern verfügbar. Alsnächstes wirdnach demersten Bildgesucht,das dem Inhalt des Beitrags hinzugefügt wurde. Wenn diesesnichtgefunden wird,wirdin der Mediengalerienach dem Bildmit der höchsten SortierunggesuchtBestellung (zumindesterinnereichmich so an die Bestellung).@matt -- In wordpress there are different ways that images can be added to posts and i think the get_the_image script just looks at one of those. This checks to see if there is a featured image and uses that one first if available, next I think it checks for the first image added to the post content and if that is not found it checks the media gallery for the image with the highest sort order (at least thats how I remember the order going).
- 1
- 2011-02-22
- NetConstructor.com
-
Ich schlage vor,http://wordpress.org/extend/plugins/auto-post-thumbnail/Generiert automatisch das Post-Thumbnail (empfohlenes Thumbnail) aus demersten Bildim Post odereinem benutzerdefinierten Post-Typnur,wenn Post-Thumbnailnichtfestgelegtisti suggest http://wordpress.org/extend/plugins/auto-post-thumbnail/ Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set
- 0
- 2011-05-08
- Ünsal Korkmaz
-
Ich überprüfenicht auf Thumbnails -bist du sicher?i dont any check for thumbnail - are you sure?
- 0
- 2012-02-21
- Sagive SEO
-
- 2010-11-14
Plugin Update Hinweis NURfür INAKTIVE Pluginsentfernen
function update_active_plugins($value = '') { /* The $value array passed in contains the list of plugins with time marks when the last time the groups was checked for version match The $value->reponse node contains an array of the items that are out of date. This response node is use by the 'Plugins' menu for example to indicate there are updates. Also on the actual plugins listing to provide the yellow box below a given plugin to indicate action is needed by the user. */ if ((isset($value->response)) && (count($value->response))) { // Get the list cut current active plugins $active_plugins = get_option('active_plugins'); if ($active_plugins) { // Here we start to compare the $value->response // items checking each against the active plugins list. foreach($value->response as $plugin_idx => $plugin_item) { // If the response item is not an active plugin then remove it. // This will prevent WordPress from indicating the plugin needs update actions. if (!in_array($plugin_idx, $active_plugins)) unset($value->response[$plugin_idx]); } } else { // If no active plugins then ignore the inactive out of date ones. foreach($value->response as $plugin_idx => $plugin_item) { unset($value->response); } } } return $value; } add_filter('transient_update_plugins', 'update_active_plugins'); // Hook for 2.8.+ //add_filter( 'option_update_plugins', 'update_active_plugins'); // Hook for 2.7.x
Remove Plugin Update Notice ONLY for INACTIVE plugins
function update_active_plugins($value = '') { /* The $value array passed in contains the list of plugins with time marks when the last time the groups was checked for version match The $value->reponse node contains an array of the items that are out of date. This response node is use by the 'Plugins' menu for example to indicate there are updates. Also on the actual plugins listing to provide the yellow box below a given plugin to indicate action is needed by the user. */ if ((isset($value->response)) && (count($value->response))) { // Get the list cut current active plugins $active_plugins = get_option('active_plugins'); if ($active_plugins) { // Here we start to compare the $value->response // items checking each against the active plugins list. foreach($value->response as $plugin_idx => $plugin_item) { // If the response item is not an active plugin then remove it. // This will prevent WordPress from indicating the plugin needs update actions. if (!in_array($plugin_idx, $active_plugins)) unset($value->response[$plugin_idx]); } } else { // If no active plugins then ignore the inactive out of date ones. foreach($value->response as $plugin_idx => $plugin_item) { unset($value->response); } } } return $value; } add_filter('transient_update_plugins', 'update_active_plugins'); // Hook for 2.8.+ //add_filter( 'option_update_plugins', 'update_active_plugins'); // Hook for 2.7.x
-
Diesistnicht unbedingteine gute Idee -ein inaktives Pluginistimmernochim Dateisystem vorhanden,undein unsicheres Plugin kann weiterhin zum Hacken der Site verwendet werden.Plugins solltenimmer auf demneuesten Standgehalten werden.This is not necessarily a good idea - an inactive plugin is still present in the filesystem, and an insecure one can still be utilised to hack the site. Plugins should always be kept up-to-date.
- 1
- 2016-04-11
- Tim Malone
-
- 2010-11-09
Entfernen Sie überflüssige Informationen und HTML-Codeim
<head>
-Tag// remove unnecessary header info add_action( 'init', 'remove_header_info' ); function remove_header_info() { remove_action( 'wp_head', 'rsd_link' ); remove_action( 'wp_head', 'wlwmanifest_link' ); remove_action( 'wp_head', 'wp_generator' ); remove_action( 'wp_head', 'start_post_rel_link' ); remove_action( 'wp_head', 'index_rel_link' ); remove_action( 'wp_head', 'adjacent_posts_rel_link' ); // for WordPress < 3.0 remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); // for WordPress >= 3.0 } // remove extra CSS that 'Recent Comments' widget injects add_action( 'widgets_init', 'remove_recent_comments_style' ); function remove_recent_comments_style() { global $wp_widget_factory; remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) ); }
Remove superfluous info and HTML within the
<head>
tag// remove unnecessary header info add_action( 'init', 'remove_header_info' ); function remove_header_info() { remove_action( 'wp_head', 'rsd_link' ); remove_action( 'wp_head', 'wlwmanifest_link' ); remove_action( 'wp_head', 'wp_generator' ); remove_action( 'wp_head', 'start_post_rel_link' ); remove_action( 'wp_head', 'index_rel_link' ); remove_action( 'wp_head', 'adjacent_posts_rel_link' ); // for WordPress < 3.0 remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); // for WordPress >= 3.0 } // remove extra CSS that 'Recent Comments' widget injects add_action( 'widgets_init', 'remove_recent_comments_style' ); function remove_recent_comments_style() { global $wp_widget_factory; remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) ); }
-
- 2010-11-13
Aktivieren Sie das Fehler-Debugging und die Protokollierungfür Live-Sites
Diesistein Code,denichgeschrieben habe,um die WP_DEBUG-Konstanten zu verwenden,dienormalerweise standardmäßig deaktiviert sind. Nun,ich habeeine Möglichkeitgeschaffen,WP_DEBUGnichtnur zu aktivieren,damit Siees aufeiner Live-Site ohnenegative Nebenwirkungen verwenden können,sondernich habe auch die anderen Debugging-Konstanten verwendet,um das Anzeigen von Fehlern zuerzwingen undeine Protokolldatei zuerstellen der Fehler und Hinweiseim Verzeichnis/wp-content.
Fügen Sie diesen Codein Ihre Datei wp-config.phpein (nachdem Sieein Backupnurfür den Fallgespeichert haben),und übergeben Sie dann die Parameter? debug=1,2 oder 3 am Endeeinerbeliebigen URL auf Ihrer Site.
? debug=1=zeigt alle Fehler/Hinweise an ? debug=2=erzwingt die Anzeige ? debug=3=erstellteine debug.log-Datei aller Fehlerim Verzeichnis/wp-content.
/** * Written by Jared Williams - http://new2wp.com * @wp-config.php replace WP_DEBUG constant with this code * Enable WP debugging for usage on a live site * http://core.trac.wordpress.org/browser/trunk/wp-includes/load.php#L230 * Pass the '?debug=#' parameter at the end of any URL on site * * http://example.com/?debug=1, /?debug=2, /?debug=3 */ if ( isset($_GET['debug']) && $_GET['debug'] == '1' ) { // Enable the reporting of notices during development - E_ALL define('WP_DEBUG', true); } elseif ( isset($_GET['debug']) && $_GET['debug'] == '2' ) { // Must be true for WP_DEBUG_DISPLAY to work define('WP_DEBUG', true); // Force the display of errors define('WP_DEBUG_DISPLAY', true); } elseif ( isset($_GET['debug']) && $_GET['debug'] == '3' ) { // Must be true for WP_DEBUG_LOG to work define('WP_DEBUG', true); // Log errors to debug.log in the wp-content directory define('WP_DEBUG_LOG', true); }
Ichgehe hiernäher auf den Gastbeitragein,denichfür Comluvgeschrieben habe,wenn Sieinteressiert sind: http://comluv.com/dev/enable -Debugging-and-Logging-für-Live-Site-Nutzung/
Ich arbeiteimmernoch daran,diesesentwederpasswortgeschützt zumachen oderes vorzugsweiseirgendwie aufif (current_user_can ('manage_themes') undis_logged_in () zu setzen.
Aber hier wirdes viel schwieriger.
Enable Error Debugging And Logging To Use On Live Sites
This is a piece of code I wrote to make use of the WP_DEBUG constants that are normally disabled by default. Well, I created a way to not only enable WP_DEBUG so you can use it on a live site with no negative side-effects, but I also made use of the other debugging constants for forcing errors to be displayed, and for creating a log file of the errors and Notices in the /wp-content directory.
Drop this code in your wp-config.php file (AFTER YOU SAVE A BACKUP JUST IN CASE) and then you can pass the ?debug=1, 2, or 3 parameters at the end of any URL on your site.
?debug=1 = shows all errors/notices ?debug=2 = forces them to be displayed ?debug=3 = creates a debug.log file of all errors in /wp-content dir.
/** * Written by Jared Williams - http://new2wp.com * @wp-config.php replace WP_DEBUG constant with this code * Enable WP debugging for usage on a live site * http://core.trac.wordpress.org/browser/trunk/wp-includes/load.php#L230 * Pass the '?debug=#' parameter at the end of any URL on site * * http://example.com/?debug=1, /?debug=2, /?debug=3 */ if ( isset($_GET['debug']) && $_GET['debug'] == '1' ) { // Enable the reporting of notices during development - E_ALL define('WP_DEBUG', true); } elseif ( isset($_GET['debug']) && $_GET['debug'] == '2' ) { // Must be true for WP_DEBUG_DISPLAY to work define('WP_DEBUG', true); // Force the display of errors define('WP_DEBUG_DISPLAY', true); } elseif ( isset($_GET['debug']) && $_GET['debug'] == '3' ) { // Must be true for WP_DEBUG_LOG to work define('WP_DEBUG', true); // Log errors to debug.log in the wp-content directory define('WP_DEBUG_LOG', true); }
I go into more detail on the guest post I wrote for Comluv if you're interested, here: http://comluv.com/dev/enable-debugging-and-logging-for-live-site-usage/
I'm still working on a way to make this either password protected, or preferrably somehow make it work on if (current_user_can('manage_themes') and is_logged_in().
But that's where it gets alot more tricky.
-
Wir verwendenetwas Ähnliches,um Live-,Staging- und Dev-Datenbankverbindungsdetailseinzurichten.We use something similar to setup live, staging and dev database connection details.
- 0
- 2011-03-07
- Tom
-
- 2010-09-10
Dynamische Titel automatisch zu öffentlichen Seiten hinzufügen
Getestet am: WordPress 3.0.1
Wenn Sie denfolgenden Code verwenden,werden automatisch dynamische Seitentitelerstellt,die auf den öffentlich angezeigten Seiten/Postsbasieren.
/* Dynamic Titles **/ // This sets your <title> depending on what page you're on, for better formatting and for SEO // You need to set the variable $longd to some custom text at the beginning of the function function dynamictitles() { $longd = __('Enter your longdescription here.', 'texdomainstring'); if ( is_single() ) { wp_title(''); echo ' | '.get_bloginfo('name'); } else if ( is_page() || is_paged() ) { bloginfo('name'); wp_title('|'); } else if ( is_author() ) { bloginfo('name'); wp_title(' | '.__('Author', 'texdomainstring')); } else if ( is_category() ) { bloginfo('name'); wp_title(' | '.__('Archive for', 'texdomainstring')); } else if ( is_tag() ) { echo get_bloginfo('name').' | '.__('Tag archive for', 'texdomainstring'); wp_title(''); } else if ( is_archive() ) { echo get_bloginfo('name').' | '.__('Archive for', 'texdomainstring'); wp_title(''); } else if ( is_search() ) { echo get_bloginfo('name').' | '.__('Search Results', 'texdomainstring'); } else if ( is_404() ) { echo get_bloginfo('name').' | '.__('404 Error (Page Not Found)', 'texdomainstring'); } else if ( is_home() ) { echo get_bloginfo('name').' | '.get_bloginfo('description'); } else { echo get_bloginfo('name').' | '.($blog_longd); } }
Automatically Add Dynamic Titles to Public Pages
Tested on: WordPress 3.0.1
Utilizing the code below will automatically create dynamic page titles based upon the pages/posts being viewed publicly.
/* Dynamic Titles **/ // This sets your <title> depending on what page you're on, for better formatting and for SEO // You need to set the variable $longd to some custom text at the beginning of the function function dynamictitles() { $longd = __('Enter your longdescription here.', 'texdomainstring'); if ( is_single() ) { wp_title(''); echo ' | '.get_bloginfo('name'); } else if ( is_page() || is_paged() ) { bloginfo('name'); wp_title('|'); } else if ( is_author() ) { bloginfo('name'); wp_title(' | '.__('Author', 'texdomainstring')); } else if ( is_category() ) { bloginfo('name'); wp_title(' | '.__('Archive for', 'texdomainstring')); } else if ( is_tag() ) { echo get_bloginfo('name').' | '.__('Tag archive for', 'texdomainstring'); wp_title(''); } else if ( is_archive() ) { echo get_bloginfo('name').' | '.__('Archive for', 'texdomainstring'); wp_title(''); } else if ( is_search() ) { echo get_bloginfo('name').' | '.__('Search Results', 'texdomainstring'); } else if ( is_404() ) { echo get_bloginfo('name').' | '.__('404 Error (Page Not Found)', 'texdomainstring'); } else if ( is_home() ) { echo get_bloginfo('name').' | '.get_bloginfo('description'); } else { echo get_bloginfo('name').' | '.($blog_longd); } }
-
- 2010-11-09
Neue Rollen und Funktionen - Nureinmal ausführen!
Ich halte diesegriffbereit,diesist der richtige Weg,um sie ohne Plugin zumachen. Sie legenein einzelnes Feld (prefix_user_roles)in der Optionsdatenbankfest,und Siebenötigen kein Plugin,um siefestzulegen. Auf der Codex-Seitefinden Sieeine Liste der verfügbaren Funktionen und Beschreibungenihrer Funktionen. Sie Siemüssennureinen dieser Blöcke auskommentieren,eine Seite laden und sie dannerneut kommentieren! Hiererstelleicheine Rollemit den Funktionen,dieichbenötige:
/* Capabilities */ // To add the new role, using 'international' as the short name and // 'International Blogger' as the displayed name in the User list and edit page: /* add_role('international', 'International Blogger', array( 'read' => true, // True allows that capability, False specifically removes it. 'edit_posts' => true, 'delete_posts' => true, 'edit_published_posts' => true, 'publish_posts' => true, 'edit_files' => true, 'import' => true, 'upload_files' => true //last in array needs no comma! )); */ // To remove one outright or remove one of the defaults: /* remove_role('international'); */
Manchmalistespraktisch,eine vorhandene Rolle hinzuzufügen/daraus zuentfernen,anstatteine zuentfernen underneut hinzuzufügen. Siemüssenesnur auskommentieren,eine Seiteneu laden und dannerneut kommentieren. Dadurch wird die Rolle/Funktion ordnungsgemäßin der Optionstabellegespeichert. (Auf diese Weise können Sie als Entwickler sie steuern und den Overhead der umfangreichen Pluginsentfernen,die dasselbetun.) Hier ändereich die Autorenrolle,umihre veröffentlichten Beiträge zu löschen (Standardeinstellung),erlaubeihnenjedoch die Möglichkeit zum Bearbeitenihre veröffentlichten Beiträge (wasfür diese Rolle standardmäßignichtmöglichist) -mit * add_cap * oder * remove_cap *.
/* $edit_role = get_role('author'); $edit_role->add_cap('edit_published_posts'); $edit_role->remove_cap('delete_published_posts'); */
Ichbehalteeine Tabellemit dem Raster von der Codex-Seitefür Websites,die auf diese Weisegeändert wurden,damitichmich daranerinnern kann,wie die Dingeeingestellt sind,obwohl das Auslassen des auskommentierten Codesin Ihrer Dateifunctions.phpfunktioniert. Lassen Sie diese Beispielenicht unkommentiert,da sie sonstbei jedem Laden der Seitein die Datenbankgeschrieben werden!
New Roles and Capabilities - Only run once!
I keep these handy, this is the right way to do them without a plugin. They set a single field (prefix_user_roles) in the options database, and you don't need a plugin to set them. Refer to the Codex page for a list of what capabilities are available and descriptions for what they do. You only need to uncomment one of these blocks, load any page and then comment them again! Here I'm creating a role that's got the capabilities I need:
/* Capabilities */ // To add the new role, using 'international' as the short name and // 'International Blogger' as the displayed name in the User list and edit page: /* add_role('international', 'International Blogger', array( 'read' => true, // True allows that capability, False specifically removes it. 'edit_posts' => true, 'delete_posts' => true, 'edit_published_posts' => true, 'publish_posts' => true, 'edit_files' => true, 'import' => true, 'upload_files' => true //last in array needs no comma! )); */ // To remove one outright or remove one of the defaults: /* remove_role('international'); */
It's sometimes handy to add/remove from an existing role rather than removing and re-adding one. Again, you only need to uncomment it, reload a page and then comment it again. This will store the role/capability properly in the options table. (This allows you, the developer to control them and removes the overhead of the bulky plugins that do the same thing.) Here I'm changing the author role to delete their published posts (the default), but allowing them the capability to edit their published posts (which isn't possible for this role by default)-- using *add_cap* or *remove_cap*.
/* $edit_role = get_role('author'); $edit_role->add_cap('edit_published_posts'); $edit_role->remove_cap('delete_published_posts'); */
I keep a spreadsheet with the grid from the Codex page for sites that modify this way, so I can remember how things are set, though leaving the commented out code in your functions.php file will work to. Don't leave these examples uncommented, or it will write to the database with each page load!
-
Die obenerwähnten Funktionen schreibenin ein Feldin der Optionsdatenbank.Sie zu kommentieren und zu kommentierenist der richtige Weg.Esgibt Pluginsfür Benutzerrollen. Wenn Siejedoch die obengenannten Funktionen verwenden,können Sie diese Funktionennicht ausführen,und Siemüssen sie NICHTmehrmalsfestlegen oderbasierend darauffestlegen,obein bestimmter Benutzer aufetwas zugreift.Wenn Sie diesmöchten,richten Sie diesen Benutzermit einerbestimmten,eindeutigen Rolleein.Undbeziehen Sie sich auf den Codex,alles,wasich oben schreibe,ist 100% korrekt,wenn Siees ohne Plugintun. Infast allen Fällenmüssen Sie die Benutzerrollennureinmalfestlegen.The functions I mention above write to a field in the options database. Commenting and uncommenting them is the way to go. There are plugins for user roles, but if you use the functions mention above, you cannot leave these functions running, and you DO NOT need to set them more than once, or set them based on if a specific user is accessing something. If you want that, set that user up with a specific, unique role. And refer to the codex, everything I write above is 100% correct if you do it without a plugin. For nearly every case, you only need to set the user roles once.
- 0
- 2011-02-02
- tomcat23
-
@tomcat23: Zur Veranschaulichung habeichesin eine Funktion verpackt,um die Rollenur hinzuzufügen,wenn sienochnichtexistiert.Nochein Hinweis: Ich denke,es wäreeinfacher,die Rolleirgendwoin der Rollenhierarchie zuplatzieren,indem Sie die Obergrenzen voneinerintegrierten Rolle abrufen und dann die Funktionen zurintegrierten Rolle hinzufügen/darausentfernen.Würdees klarer und leichtermachen,sich zuerinnern,ob die Kappenirgendwo zwischenexplatziert sind.Admin und Editor.- Ich hoffe,esmacht Ihnennichts aus,dassich Ihre Antwortbearbeitet habe.Wenn Sie diestun,rollen Sieesbitte zurück.:) :)@tomcat23: To illustrate, i wrapped it up in a function to only add the role, when it doesn't already exists. Another note: I guess it would be easier to place the role somewhere in the role hierarchy, with retrieving the caps from some built in role and then add/remove the capabilities from the built in role. Would make it more clear and easier to remember if it's caps are placed somewhere between ex. admin and editor. - I hope you don't mind that i edited your answer. If you do, pls role it back. :)
- 0
- 2011-03-01
- kaiser
-
Ich stehe zumeiner Antwort,alsich sie verließ.Ihre Funktion verfehlt den Punkt und liefertnicht diegleiche Antwort wiemein Text.Ichfindees auch ziemlich unhöflich,dass Siemeinen Code ändern und antworten.I stand by my answer as I left it. Your function misses the point and doesn't provide the same answer as my text. I also it's quite rude of you do change my code and answer.
- 0
- 2011-03-11
- tomcat23
-
Nichtnur das,aber Ihre Funktionmachtnicht dasselbe wiemein Code.Ihre Funktion lässtnurnocheine Überprüfung an Ort und Stelle,get_role ('international',dienichtbenötigt wird! Ich habe diesen Code zum Verschiebeneines Clients verwendet,dereinen Server hatte,der PHP4 verwendete und daher das Rollenscoper-Pluginnicht verwenden konnteverwendet,das warnur PHP5. (Und war daseinzige Plugin,das PHP5fürihre Installationbenötigte.) Als Entwickler sahich,dass dereinzige Grund,warum sieesbrauchten,darinbestand,ein paar Rolleneinzurichten undeinige Funktionen zu ändernCode,**meine ursprüngliche Antwort hier **,ist,wie dasgeht!Not only that, but your function doesn't do the same thing as my code. Your function leaves just one more check in place, get_role('international', that isn't needed! I used this code for moving a client who had a server that was using php4 and therefore couldn't use the role scoper plugin they had been using, which was php5 only. (And was the only plugin that needed php5 for their install.) As a developer, I saw that the only reason they needed it was to set up a couple of roles and change some capabilities. And this code, **my original answer here**, is how to do that!
- 0
- 2011-03-12
- tomcat23
-
Siemüssen und sollten diesnichtin eine Funktioneinschließen.Siebrauchenesnur,um die Rollen und Funktionen richtigeinzustellen.Wenn Siemit ihnen herumspielenmöchten,gibt eseinige großartige (wenn auch aufgeblähte) Plugins dafür. Wenn Sie die Rollen und Funktionenin WordPress verstehen undnichtnur damit herumstöbern und keineigenes Plugin schreiben,können Sie dies richtigmachen.Bittebearbeiten Siemeinen Codenicht.Ich habees zurückgerollt.Ihre Funktionsumhüllungistin der Geschichtefürjeden sichtbar,obwohlichnichtmit dem übereinstimme,was Siegetan haben.You do not need to, nor should you, wrap this in a function. You just need it to properly set the roles and capabilities. If you want to play around with them, there's some great (though bloated) plugins for that. If you understand the roles and capabilities in wordpress and aren't just poking around with it, and aren't writing your own plugin, then this is how to do it right. Please don't edit my code. I have rolled it back. Your function wrapping is in the history for anyone to see, though I disagree with what you have done.
- 0
- 2011-03-12
- tomcat23
-
Um dies weiter zu verdeutlichen,müssen Sie diesnichtin eine Funktioneinschließen oder Administratorprüfungen durchführen.** add_role (),remove_role (),add_cap () und remove_cap ()müssen,wieichin meiner ursprünglichen Antwortgezeigt habe,nichtimmer wieder ausgeführt werden - sie setzen lediglichein Feldin der Optionstabelle,dasnichtbenötigt wirdimmer wiedergeschrieben werden - weshalb Ihr Funktions-Wrapperfalschist. ** Ich weiß,Siefügen after_setup_themeeine Aktion hinzu,aber das Festlegeneiner Rollemit diesem Hook warnicht das,worumesin meiner Antwortging.(Undim Allgemeinenmüssen Rollennichtmit Themen verpackt sein.)To clarify further, you **do not need** to wrap this in a function or do admin checks. **add_role(), remove_role(), add_cap() and remove_cap(), as I show in my original answer do not need to be executed over and over -- they just set a field in the options table that does not need to be written to over and over again -- which is why your function wrapper is wrong.** I know, you are adding an action to after_setup_theme, but setting a role with that hook is not what my answer was about. (And generally roles don't need to come packaged with themes.)
- 0
- 2011-03-12
- tomcat23
-
Puh ... Wieich schrieb: "Ich hoffe,esmacht dirnichts aus,dassich deine Antwortbearbeitet habe. Wenn du dastust,rolle siebitte zurück. :)".Sie habenes zurückgespielt,Ihren Grunderklärt und wissen was: Esistin Ordnung.Alsoberuhige dich.Aber um Ihnen diegleiche Menge an Erklärungen zubieten: Ich verpackeimmer Dingein Funktionen undfüge siemeinem Testdateienordnermeines Themas hinzu.Auf diese Weise kannich leicht Sachen zum Beispieltesten.WA antwortet undfügt sie schnell hinzu,wennichetwasbrauche,alsoistesin Ordnung,esin eine Funktion zupacken.Außerdemisteseinfacher,(nur den Aufruf add_action) zu deaktivieren und Dokumentkommentaremit/**/anstelle vonmehrzeiligen//Kommentaren zuzulassen.Soviel zumeinem "Warum".Puh... As i wrote: "I hope you don't mind that i edited your answer. If you do, pls role it back. :)". You roled it back, explained your reason and guess what: It's ok. So calm down. But to offer you the same amount of explanation: I always wrap stuff in functions and add it to my test files folder of my theme. This way i can easily test stuff for ex. WA answers and add them quickly if i need anything, so wrapping it in a function is ok. Further more it's easier to disable (only the add_action call) and allow doc-comments with /**/ instead of multiline // comments. That much about my "why".
- 0
- 2011-03-12
- kaiser
-
@tomcat23 - Beachten Sie,dass wireine Community sind,die sichgegenseitig unterstützt und sichnichtgegenseitig herausfordert,außer dies akademisch zutun.Wie Sie aus der Antwort von @ kaiser sehen,haternur versucht zu helfen.@tomcat23 - Note that we are a community that is supportive of each other, not one that challenges each other except to do so academically. As you see from @kaiser's response, he was just trying to help.
- 0
- 2011-03-12
- MikeSchinkel
-
@MikeSchinkel Icherinneremich,dasses am 1. Februar zwei Kommentare von @kaisergab,weshalbich dann sogeantwortet habe,wieichesgetan habe.(Sie sind Moderator,können Sie sehen,oberesgetan hat? Weilichnichtglaube,dassichfalsch liege,wenner 2 Kommentare zumeiner Verwendung hat,dieeinfachnichtgut zuihmpassen.) Ich hattenicht das Gefühl,dassmein Code odermeine Erklärung Hilfebenötigenund sagteesihm am 1. Februar.Ich kommeeinige Zeit später zurück und stellefest,dassermeinen Codegeändert hat -meine erste Begegnungmit dem "Wiki" -Aspekt dieser Site - undich warmeiner Meinungnach zu Recht verärgert darüber,dassmein Text undmeine Kommentareeine Sachebesprechen,den Code selbstwar anders.@MikeSchinkel I recall there being two comments by @kaiser on Feb 1, which is why I responded then how I did. (You are moderator, can you see if he did? Because I don't think I'm wrong in thinking he had 2 comments about my usage just not sitting well with him.) I did not feel that my code or explanation needed help and told him so on Feb 1st. I come back some time later and find that he's changed my code -- my first exposure to this site's "wiki" aspect -- and I was, in my opinion, justifiably annoyed that while my text and comments discuss one thing, the code itself was different.
- 0
- 2011-03-13
- tomcat23
-
Meine Antwortistim Geiste der ursprünglichen Frage.Diesistmein nützlicher Code. Diesfunktioniertgutfürmich undich verwendeihnnichtin einer Funktion.Wenn @kaiser diese Fragemit dem Codebeantworten wollte,derin eine Funktioneingeschlossen und aneinen Hook angehängtist,kanner diesimmernochtun. Wiederum @kaiser,was Siegetan haben,ummeinen Code zu ändern,abernichtmeinen Text,war schädlichfür andere Leute,die hierher kamen,es sahen undfeststellten,dassmeine Diskussion über den Code keinen Sinnergab.Deshalbfindeiches unhöflich von Ihnen,das zutun,was Siegetan haben,und warumichgesterngenauso hart reagiert habe wieich.My answer is in the spirit of the original question. This is _my_ useful code, this is what works well for me and I don't use it wrapped in a function. If @kaiser had wanted to answer this question with the code wrapped in a function and attached to a hook, he's still free to do so. Again, @kaiser what you did in changing my code but not my text was detrimental to other people who would come here, see it and find that my discussion of the code made no sense. That is why I feel it is rude of you to do what you did and why I responded yesterday as harshly as I did.
- 0
- 2011-03-13
- tomcat23
-
@tomcat23 - Wasser unter der Brücke an dieser Stelle.Ich sagenur,ichbin nicht daraninteressiert,Schuld zugeben,sondernnur Friedenfür alle zu haben,die sich weiterentwickeln.:) :)@tomcat23 - Water under the bridge at this point. All I'm saying is, I'm not interested in placing blame, just in having peace for everyone moving forward. :)
- 1
- 2011-03-13
- MikeSchinkel
-
@ MikeSchinkel Ja,du hast recht. @kaiser Ichentschuldigemich,wennich dichbeleidigt habe.@MikeSchinkel Yes, you are right. @kaiser My apologies if I've caused you insult.
- 2
- 2011-03-13
- tomcat23
-
@ MikeSchinkel: Danke,dass du wieder Friedengebracht hast. @ Tomcat23: Nein,hast dunicht.Ich kannmit dieser Art von Kritik umgehen.Ichentschuldigemich auch.@MikeSchinkel: thanks for bringing peace back in. @tomcat23: No, you didn't. I can deal with that sort of criticism. My apologies too.
- 1
- 2011-03-13
- kaiser
-
- 2010-11-14
Aktivieren Sie Shortcodesin Widgets
// shortcode in widgets if ( !is_admin() ){ add_filter('widget_text', 'do_shortcode', 11); }
Enable shortcodes in widgets
// shortcode in widgets if ( !is_admin() ){ add_filter('widget_text', 'do_shortcode', 11); }
-
- 2010-12-28
Wordpress Custom Admin Footer
//Admin-Fußzeilentext anpassen Funktion custom_admin_footer () { Echo 'Fügen Sie hier Ihrenbenutzerdefinierten Fußzeilentext und HTML hinzu'; }} add_filter ('admin_footer_text','custom_admin_footer');
Ich verwende diesfür Client-Sites alseinfachen Bezugspunkt,ummich als Entwickler zu kontaktieren.
Wordpress Custom Admin Footer
// customize admin footer text function custom_admin_footer() { echo 'add your custom footer text and html here'; } add_filter('admin_footer_text', 'custom_admin_footer');
I use this for client sites as a simple point of reference to contact me as the dev.
-
- 2010-09-12
Funktion zum Deaktivieren von RSS-Feeds
Getestet am: Wordpress 3.0.1
Sie können RSS-Feeds deaktivieren,wenn Sie Ihre Wordpress-basierte Website als statischbeibehaltenmöchten.
Sie können diese Funktion verwenden:
function fb_disable_feed() { wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') ); } add_action('do_feed', 'fb_disable_feed', 1); add_action('do_feed_rdf', 'fb_disable_feed', 1); add_action('do_feed_rss', 'fb_disable_feed', 1); add_action('do_feed_rss2', 'fb_disable_feed', 1); add_action('do_feed_atom', 'fb_disable_feed', 1);
Function to Disable RSS Feeds
Tested on: Wordpress 3.0.1
You can disable RSS feeds If you want to maintain your Wordpress based website as static.
You can Use this function :
function fb_disable_feed() { wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') ); } add_action('do_feed', 'fb_disable_feed', 1); add_action('do_feed_rdf', 'fb_disable_feed', 1); add_action('do_feed_rss', 'fb_disable_feed', 1); add_action('do_feed_rss2', 'fb_disable_feed', 1); add_action('do_feed_atom', 'fb_disable_feed', 1);
-
Quelle: http://bueltge.de/wordpress-feeds-deaktivieren/794/(Frank Bueltge)Source: http://bueltge.de/wordpress-feeds-deaktivieren/794/ (Frank Bueltge)
- 0
- 2010-09-16
- fuxia
-
Danke Toscho! Die Quelleist auchin Englisch verfügbar. http://wpengineer.com/287/disable-wordpress-feed/Thanks Toscho! the source is also available in english http://wpengineer.com/287/disable-wordpress-feed/
- 0
- 2010-09-17
- bueltge
-
- 2010-12-28
Ändern Sie die Nachricht "Grüß dich"in "Willkommen"
Mit dieser Funktion können Sie die Nachricht "Grüß dich" oben rechtsin Ihrem Administrationsbereich anpassen.
Diese Funktion verwendet JQuery,um die Nachricht "Howdy"in "Welcome" zu ändern./****** Customize admin message "Howdy" to "Welcome" ******/ $nohowdy = "Welcome"; if (is_admin()) { add_action('init', 'artdev_nohowdy_h'); add_action('admin_footer', 'artdev_nohowdy_f'); } // Load jQuery function artdev_nohowdy_h() { wp_enqueue_script('jquery'); } // Modify function artdev_nohowdy_f() { global $nohowdy; echo <<<JS <script type="text/javascript"> //<![CDATA[ var nohowdy = "$nohowdy"; jQuery('#user_info p') .html( jQuery('#user_info p') .html() .replace(/Howdy/,nohowdy) ); //]]> JS; }
PHP-Versionmit
gettext
-Filter:add_filter('gettext', 'change_howdy', 10, 3); function change_howdy($translated, $text, $domain) { if (!is_admin() || 'default' != $domain) return $translated; if (false !== strpos($translated, 'Howdy')) return str_replace('Howdy', 'Welcome', $translated); return $translated; }
Change the "Howdy" message to "Welcome"
With this function you can customize the "Howdy" message in top right of your admin area.
This function make use of JQuery to change the "Howdy" message to "Welcome"./****** Customize admin message "Howdy" to "Welcome" ******/ $nohowdy = "Welcome"; if (is_admin()) { add_action('init', 'artdev_nohowdy_h'); add_action('admin_footer', 'artdev_nohowdy_f'); } // Load jQuery function artdev_nohowdy_h() { wp_enqueue_script('jquery'); } // Modify function artdev_nohowdy_f() { global $nohowdy; echo <<<JS <script type="text/javascript"> //<![CDATA[ var nohowdy = "$nohowdy"; jQuery('#user_info p') .html( jQuery('#user_info p') .html() .replace(/Howdy/,nohowdy) ); //]]> JS; }
PHP version, using
gettext
filter:add_filter('gettext', 'change_howdy', 10, 3); function change_howdy($translated, $text, $domain) { if (!is_admin() || 'default' != $domain) return $translated; if (false !== strpos($translated, 'Howdy')) return str_replace('Howdy', 'Welcome', $translated); return $translated; }
-
Kann diesnichtbereits auf der PHP-Seitebearbeitet werden,damites überhauptnicht ausgegeben wird?Can't this already be edited on the PHP side so it doesn't get output at all?
- 3
- 2011-02-14
- hakre
-
Esfunktioniert hier sicherin Versionen ab 3.0gut,aber warumnichtin älteren Versionen?Überprüfen Sie,obein anderes von Ihnen verwendetes Plugin dafür verantwortlichist.Der Text hier wurde durch JQueryersetzt,vielleichtein JQuery-Plugin?It's working fine here in 3.0+ versions for sure, but why not in older versions? Check if any other plugin you use is responsible for this. The text here replaced with JQuery, maybe a JQuery plugin?
- 0
- 2011-02-14
- Philip
-
- 2011-01-26
Fügen Siebenutzerdefinierte Beitragstypenin "Im Moment"ein. Admin-Dashboard
Dies umfasst Ihrebenutzerdefinierten Beitragstypen und die Anzahl der Beiträgefürjeden Typim & quot; "Jetzt". Dashboard-Widget.
// ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET function wph_right_now_content_table_end() { $args = array( 'public' => true , 'show_ui' => true , '_builtin' => false ); $output = 'object'; $operator = 'and'; $post_types = get_post_types( $args , $output , $operator ); foreach( $post_types as $post_type ) { $num_posts = wp_count_posts( $post_type->name ); $num = number_format_i18n( $num_posts->publish ); $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) ); if ( current_user_can( 'edit_posts' ) ) { $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>"; $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>"; } echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>'; echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>'; } $taxonomies = get_taxonomies( $args , $output , $operator ); foreach( $taxonomies as $taxonomy ) { $num_terms = wp_count_terms( $taxonomy->name ); $num = number_format_i18n( $num_terms ); $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms )); if ( current_user_can( 'manage_categories' ) ) { $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>"; $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>"; } echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>'; echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>'; } } add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
Include custom post types in "Right Now" admin dashboard
This will include your custom post types and the post counts for each type in the "Right Now" dashboard widget.
// ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET function wph_right_now_content_table_end() { $args = array( 'public' => true , 'show_ui' => true , '_builtin' => false ); $output = 'object'; $operator = 'and'; $post_types = get_post_types( $args , $output , $operator ); foreach( $post_types as $post_type ) { $num_posts = wp_count_posts( $post_type->name ); $num = number_format_i18n( $num_posts->publish ); $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) ); if ( current_user_can( 'edit_posts' ) ) { $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>"; $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>"; } echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>'; echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>'; } $taxonomies = get_taxonomies( $args , $output , $operator ); foreach( $taxonomies as $taxonomy ) { $num_terms = wp_count_terms( $taxonomy->name ); $num = number_format_i18n( $num_terms ); $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms )); if ( current_user_can( 'manage_categories' ) ) { $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>"; $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>"; } echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>'; echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>'; } } add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
-
Plötzlicherschienim RightNow-Widgetein Beitragstyp "WooFramework Internal Container"!...Ein zusätzliches Argument wirdbenötigt "show_ui"=>true "undjetztist alles K.Suddenly, there was a post type "WooFramework Internal Container" appearing in the RightNow widget! . . . one extra argument is needed `'show_ui' => true` and it's all K now
- 0
- 2012-04-04
- brasofilo
-
Diesistgenau das,wasich obengepostet hatte.This is the same exact thing I had posted above.
- 0
- 2012-12-09
- jaredwilli
-
- 2010-11-09
Fügen Sie dem Dashboard-Headerein Codex-Suchformular hinzu.
Diesisteine einfache Möglichkeit,ein Codex-Suchformular zum Dashboard-Header oben rechtsneben dem Dropdown-Menüfür Quicklinks hinzuzufügen.
/** * ADD WP CODEX SEARCH FORM TO DASHBOARD HEADER */ function wp_codex_search_form() { echo '<form target="_blank" method="get" action="http://wordpress.org/search/do-search.php" class="alignright" style="margin: 11px 5px 0;"> <input type="text" onblur="this.value=(this.value==\'\') ? \'Search the Codex\' : this.value;" onfocus="this.value=(this.value==\'Search the Codex\') ? \'\' : this.value;" maxlength="150" value="Search the Codex" name="search" class="text"> <input type="submit" value="Go" class="button" /> </form>'; } if( current_user_can( 'manage_plugins' )) { // The number 11 needs to be a 10 for this to work! add_filter( 'in_admin_header', 'wp_codex_search_form', 11 ); }
Add a codex search form to the dashboard header
This is a simple way to add a codex search form to the dashboard header, on the top-right next to the quicklinks drop-down.
/** * ADD WP CODEX SEARCH FORM TO DASHBOARD HEADER */ function wp_codex_search_form() { echo '<form target="_blank" method="get" action="http://wordpress.org/search/do-search.php" class="alignright" style="margin: 11px 5px 0;"> <input type="text" onblur="this.value=(this.value==\'\') ? \'Search the Codex\' : this.value;" onfocus="this.value=(this.value==\'Search the Codex\') ? \'\' : this.value;" maxlength="150" value="Search the Codex" name="search" class="text"> <input type="submit" value="Go" class="button" /> </form>'; } if( current_user_can( 'manage_plugins' )) { // The number 11 needs to be a 10 for this to work! add_filter( 'in_admin_header', 'wp_codex_search_form', 11 ); }
-
Können Sie diesen Code aktualisieren,um zu zeigen,wie diesnur Benutzernmit einerbestimmten Rolle (insbesondere Administratoren) angezeigt wird?can you update this code to show how this only gets displayed to users with a specific role (specifically administrators)?
- 0
- 2011-02-22
- NetConstructor.com
-
@ NetConstructor.com Ich habeesbearbeitet,um anzuzeigen,ob current_user_ Plugins verwalten kann,und dann den Filter hinzugefügt.Soeinfachist das.@NetConstructor.com I edited it to show if current_user_can manage plugins, then add the filter. It's that simple.
- 1
- 2011-02-23
- jaredwilli
-
Funktioniert dasnochin der aktuellen WP-Version ... Ich konnteesnicht zum LaufenbringenDoes this still work in the current WP version... I couldn't get it to work
- 1
- 2012-02-15
- Zach Lysobey
-
Ich habe den add_filterin diesem Aktionsaufrufgekapselt: ** add_action ('plugins_loaded','pluginInit'); ** und dann `functionpluginInit () {if ... add_filter (...)}` - -i'mFühren Sie diesin WP 3.4-alpha aus undmussten **in_admin_footer ** verwendenI encapsulated the add_filter in this action call: **add_action('plugins_loaded', 'pluginInit');**, and then `function pluginInit(){if...add_filter(...)}` - - i'm running this in WP 3.4-alpha, and had to use **in_admin_footer**
- 0
- 2012-04-02
- brasofilo
-
- 2010-11-14
Neue Medienbibliotheksspalte zumerneuten Anhängen von Bildern
Dieser Codefügt der Medienbibliothekseiteeine neue Spalte hinzu,mit der Sie Bildererneut anhängen können
add_filter("manage_upload_columns", 'upload_columns'); add_action("manage_media_custom_column", 'media_custom_columns', 0, 2); function upload_columns($columns) { unset($columns['parent']); $columns['better_parent'] = "Parent"; return $columns; } function media_custom_columns($column_name, $id) { $post = get_post($id); if($column_name != 'better_parent') return; if ( $post->post_parent > 0 ) { if ( get_post($post->post_parent) ) { $title =_draft_or_post_title($post->post_parent); } ?> <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?> <br /> <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Re-Attach'); ?></a> <?php } else { ?> <?php _e('(Unattached)'); ?><br /> <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a> <?php } }
New Media Library Column to Re-Attach Images
This code adds a new column to the Media Library Page allowing you to re-attach images
add_filter("manage_upload_columns", 'upload_columns'); add_action("manage_media_custom_column", 'media_custom_columns', 0, 2); function upload_columns($columns) { unset($columns['parent']); $columns['better_parent'] = "Parent"; return $columns; } function media_custom_columns($column_name, $id) { $post = get_post($id); if($column_name != 'better_parent') return; if ( $post->post_parent > 0 ) { if ( get_post($post->post_parent) ) { $title =_draft_or_post_title($post->post_parent); } ?> <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?> <br /> <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Re-Attach'); ?></a> <?php } else { ?> <?php _e('(Unattached)'); ?><br /> <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a> <?php } }
-
- 2010-11-16
Setzt den Editor standardmäßig auf WYSIWYG oder HTML
function my_default_editor() { $r = 'tinymce'; // html or tinymce return $r; } add_filter( 'wp_default_editor', 'my_default_editor' );
Soentfernen Sie den HTML-Editor
jQuery(document).ready(function($) { $("#edButtonHTML").remove(); });
AKTUALISIERT Hieristeine andere Möglichkeit,den Standardeditor auf HTML
zu setzenadd_filter('wp_default_editor', create_function('', 'return "html";'));
Set Editor Defaults to WYSIWYG or HTML
function my_default_editor() { $r = 'tinymce'; // html or tinymce return $r; } add_filter( 'wp_default_editor', 'my_default_editor' );
Here is how to remove the HTML Editor
jQuery(document).ready(function($) { $("#edButtonHTML").remove(); });
UPDATED here is another way to set the default editor to HTML
add_filter('wp_default_editor', create_function('', 'return "html";'));
-
Weitere Informationen zum Ursprungfinden Sie unter: http://wpengineer.com/1946/disable-html-editor-wordpress/see more informations on the origin: http://wpengineer.com/1946/disable-html-editor-wordpress/
- 0
- 2010-11-17
- bueltge
-
- 2010-09-30
Autoren-Metabox/Optionenentfernen & amp; Gehen Sie zur Veröffentlichung der MetaBox
Getestet am: Wordpress 3.0.1
Eines der Dinge,diemich verrücktmachen,istein überfüllter Wordpress-Verwaltungsbereich. Eines der Elemente,dieichjetztimmer von Anfang anin meiner Dateifunctions.phpeinrichte,ist das Entfernen der Autoren-MetaBox und der Bildschirmoptionen und das Hinzufügen der Option zur Veröffentlichungsmetabox. Meiner Meinungnachmacht daseinfach Sinn und hält die Dinge sauber. Diesgilt auchfürgeltende Berechtigungen.
Um dieses Ziel zuerreichen,kopieren Sieeinfach denfolgenden Code undfügen Sieihnin Ihre Dateifunctions.phpein.
Wenn Sie der Meinung sind,dasseseinen besseren Weggibt,schlagen Sie diesbitte vor.
HINWEIS: AKTUALISIERT DEN CODE,UM EIN CODIERUNGSFRAGE ZU BEHEBEN
// MOVE THE AUTHOR METABOX INTO THE PUBLISH METABOX add_action( 'admin_menu', 'remove_author_metabox' ); add_action( 'post_submitbox_misc_actions', 'move_author_to_publish_metabox' ); function remove_author_metabox() { remove_meta_box( 'authordiv', 'post', 'normal' ); } function move_author_to_publish_metabox() { global $post_ID; $post = get_post( $post_ID ); echo '<div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">Author: '; post_author_meta_box( $post ); echo '</div>'; }
Remove Author Metabox/Options & Move to Publish MetaBox
Tested on: Wordpress 3.0.1
One of the things that drive me crazy is a cluttered Wordpress Admin area. One of the elements which I now always setup from the start in my functions.php file is removing the Author MetaBox and Screen Options and then adding the option into the publish metabox. In my opinion this just makes sense and keep things clean. This also respects applicable permissions.
To achieve this goal, just copy and past the following code into your functions.php file.
If you feel there is a better way of doing this please suggest.
NOTE: UPDATED THE CODE TO FIX A CODING ISSUE
// MOVE THE AUTHOR METABOX INTO THE PUBLISH METABOX add_action( 'admin_menu', 'remove_author_metabox' ); add_action( 'post_submitbox_misc_actions', 'move_author_to_publish_metabox' ); function remove_author_metabox() { remove_meta_box( 'authordiv', 'post', 'normal' ); } function move_author_to_publish_metabox() { global $post_ID; $post = get_post( $post_ID ); echo '<div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">Author: '; post_author_meta_box( $post ); echo '</div>'; }
-
Die Autoren-Metabox wirdnicht zumeiner Veröffentlichungsbox hinzugefügt.Ich dachte,das lag daran,dassesfür die Funktion "move_author_to_publish_box" keine "add_action"gab,alsofügteich "add_action" ("admin_menu","move_author_to_publish_box") hinzu.) "**It doesn't add the Author Metabox to my Publish Box. I figured it was because there was no `add_action` for the `move_author_to_publish_box` function so I added `add_action('admin_menu', 'move_author_to_publish_box');` but that gave me a **"Fatal error: Call to undefined function post_author_meta_box()"**
- 0
- 2010-12-05
- matt
-
Welche Version von WordPress verwenden Sie?what version of wordpress are you using?
- 0
- 2010-12-06
- NetConstructor.com
-
Und wie würden Sie den Autor zur Veröffentlichung hinzufügen?Auf admin_init oder auf admin_menu würdenichtfunktionieren.And how would you add the author to publish? On admin_init or on admin_menu wouldn't work.
- 0
- 2011-02-01
- kaiser
-
@kaiser - Ichbin nicht sicher,obich Ihre Frage verstehe.Dieser Codeentfernt lediglich die Metabox "Autor" undplatziert die Option zum Auswählen des Autorsin der Metabox "Veröffentlichen".@kaiser -- I am not sure I understand your question. This code just removes the "author" metabox and places the option to select the author into the "publish" metabox.
- 0
- 2011-02-01
- NetConstructor.com
-
@ NetConstructor: Ich habeesgestern (3.0.4)getestet undja,das Autorenfeldist weg,abernichtin das Veröffentlichungsfeld verschoben.Wennichmir den Code ansehe,kannich keine Möglichkeiterkennen,da die Funktionnicht ausgelöst wird ... Sie habengerade den Befehl remove_author_box ()fn zum Aktionshaken admin_menu hinzugefügt,abernicht den Befehlmove_author_to_publish_box ()fn.@NetConstructor: I just gave it a test yesterday (3.0.4) and yes, the author box is gone, but not moved to the publish box. When looking at the code i can't see any way, because the function is no where triggered... you just added the remove_author_box() fn to admin_menu action hook, but not the move_author_to_publish_box() fn.
- 1
- 2011-02-01
- kaiser
-
@kaiser - Ihr Recht,nachdemich dies überprüft habe,habeich das Problembemerkt.Ich habe den Codein meiner Antwort aktualisiert. Löschen Sie alsoeinfach alles,was Sie zuvor aus diesem Code aufgenommen haben,undfügen Sieihneinfachin den obigen Codeein.Lassen Siemich wissen,ob dies die Problemebehebt.Stimmen Sie die Frage ab undbeantworten Sie sie,wenn das Problembehobenist - CH :)@kaiser -- your right, after reviewing this I did noticed the issue. I updated the code in my answer so just delete everything you included from this before hand and just past in the full code above. Let me know if this fixes things. Vote up the question and answer if it fixes the problem - CH :)
- 1
- 2011-02-01
- NetConstructor.com
-
@ CH/NC: Sicherfunktioniertes,mussesnichteinmaltesten.Abstimmung:n/p.Könnte/sollteerweitert werden,um aucheinige der anderen Mist/Cluter zu halten ... (Diskussionen,Post Thumbnail).Ich werde Ihre Antwortnicht ändern,aber wenn Sieetwas Zeit hätten,wärees sogareinen Blog-Beitrag wert.:) :)@CH/NC: Sure it works, don't even have to test it. Voting up: n/p. Could/Should be extended to hold some of the other crap/cluter too... (discussions, post thumbnail). I'm not going to mod your answer, but if you got some time, it would even be worth a blog-post. :)
- 0
- 2011-02-01
- kaiser
-
@kaiser -nichtganz sicher,wo Sie Wert darin sehen?Mein Ziel waresnur,einige der zusätzlichen undnichtbenötigten Metaboxen wie Schnecken und Autoren zuentfernen.@kaiser -- not exactly sure where you see value in this? My objective was just to remove some of the metaboxes which were extra and unneeded such as slugs and authors.
- 0
- 2011-02-02
- NetConstructor.com
-
@you: Nein,ich sehe absolut den Vorteil.Du hastmichnichtnurmissverstanden,du hastmich um 180 Gradfalsch verstanden.Ich sagte,dasses sogutist,dasses a) auf Diskussionen und Miniaturansichten ausgedehnt wird undb)einen Blog-Beitrag darüber hat,"Inhaltebearbeiten Seiten" oder so.Bearbeiten: Ohne Notwendigkeit zutestenbedeutet,dassich weiß,dassesfunktioniert.@you: No, i absolutely see the benefit. You didn't only missunderstand me, you got me wrong by 180 degree. I said that it's that good that it should a) be extended to discussions & thumbnails and b) have a blog post about it "decluttering content edit pages" or so. Edit: With no need for testing means, that i know that it works.
- 0
- 2011-02-02
- kaiser
-
@kaiser - schätzen Sie das Kompliment,aber wasichimmernochnicht verstehe,ist,wie Sie sehen,dassesfür Benutzer von Vorteil wäre,Diskussionen oder Miniaturansichtenin die Veröffentlichungs-Metabox zuintegrieren.Ich habenur den Vorteilgesehen,die Slug- und Author-Metaboxen zuentfernen,da diese logischerweisein der Publish-Metaboxenthalten sein sollten.Versteheich Ihren Standpunktimmernochfalsch?@kaiser -- appreciate the compliment however what I still don't understand is how you see it would be of benefit to users to have discussions or thumbnails integrated into the publish metabox. I only saw the benefit of removing the slug and author metaboxes as those logically should be within the publish metabox. Am I still misunderstanding your point?
- 0
- 2011-02-03
- NetConstructor.com
-
@ NC: Nein,du hastmich richtig verstanden.Fürmichistesnicht "die Veröffentlichungsbox",sondernnureine Box oben rechtsfür kleine Dinge.Ich sehe keine Notwendigkeit,fürjedeeinzelne Textzeile "Miniaturansicht hinzufügen" oder diebeiden Kontrollkästchen aus Diskussionenein separates Feld zu haben.Nichts anderes.@NC: No, you got me right. For me it's not "the publish box", but just a box on the upper right side for small stuff. I don't see a need to have a separate box for each the single "add thumbnail" text line or the two checkboxes from discussions. Nothing else.
- 0
- 2011-02-03
- kaiser
-
- 2010-11-05
Server schnellbestimmen & amp; Umgebungsdetails
Wenn Siemehrere Server undmehrere Umgebungen wie Entwicklungs-,Qualitätssicherungs- und Produktionsumgebungen haben,kann dies sehrnützlich sein.
Beimeinen Systemen wird die Umgebung durch dieersten drei Buchstaben des Hostnamensbestimmt. Dies kannjedoch leicht an Ihre Anforderungen angepasst werden.
add_action( 'admin_notices', 'report_environment_status', 3 ); // Report on which server and environment details function report_environment_status() { $server = php_uname('n'); switch (strtolower(substr($server,0,3))) { case 'pXX': $msg = "PRODUCTION"; break; case 'qXX': $msg = "QA"; break; case 'dXX': $msg = "DEVELOPMENT"; break; default : $msg = 'UNKNOWN'; } echo "<div id='update-nag'>"; echo "<b>You are in the $msg environment. (Server: $server)</b>"; echo "</div>"; }
Dies hatmich viele Male davorbewahrt,Aktualisierungenin derfalschen Umgebung vorzunehmen.
Sie können dies auchin ein Plugin verwandeln und das Netzwerk aktivieren,damit alle Sites die Benachrichtigungerhalten.
Quickly Determine Server & Environment Details
If you have multiple servers and multiple environments such as development, QA, and production environments, this can be very useful.
For my systems, environment is determined by the first 3 letters of the hostname, but this could easily be changed to whatever suits your needs.
add_action( 'admin_notices', 'report_environment_status', 3 ); // Report on which server and environment details function report_environment_status() { $server = php_uname('n'); switch (strtolower(substr($server,0,3))) { case 'pXX': $msg = "PRODUCTION"; break; case 'qXX': $msg = "QA"; break; case 'dXX': $msg = "DEVELOPMENT"; break; default : $msg = 'UNKNOWN'; } echo "<div id='update-nag'>"; echo "<b>You are in the $msg environment. (Server: $server)</b>"; echo "</div>"; }
This has saved me many times from making updates to the wrong environment.
You can also turn this into a plugin and network activate it so all sites get the notification.
-
Dankefür dieses Stück.Könnten Siebitte etwasnäher auf diesen und verschiedene Anwendungsfälleeingehen?Ich denke,es wäre auch SEHR hilfreichfürmich und andere,wenn Siemöglicherweise anderen Codeeinfügen könnten,den Sie verwenden,wenn Sie verschiedene Entwicklungsversionen von Code ausführen.Wenn Sieeine Website aufeinfache Weise von der Entwicklungin die Produktion verschieben oder voneiner Domänein eine anderemigrierenmöchten.All diese Dinge sind sehr hilfreich.Verwenden Sie zum Aktualisieren Ihrer Dateieneinen Subversion-Client?Wennja,gibt esetwas Spezielles,das Sie dafürtun?thanks for this piece. Could you please elaborate a bit more on this and different usage cases? I think it would also be VERY helpful to me and others if you could possibly include any other code which you utilize when your running different development versions of code. Also, if you utilize a slick way of moving a site from development to production or migrate from one domain to a different one. All these things are very helpful. Finally, do you use any type of subversion client when updating your files? If so, is there anything specific you do for this?
- 0
- 2010-11-05
- NetConstructor.com
-
Bittemarkieren Sie diesnicht als Antwort.Andernfallsfunktioniert diese Auflistungnicht.Please don't mark this as the answer. Otherwise this listing won't work.
- 0
- 2010-11-06
- hakre
-
Ich denke,es wärebesser,verschiedene CSS-Klassenfür die Nachricht zu verwenden,damit die Nachrichtenin Umgebungen unterschiedliche Hintergrundfarben haben undnur leicht unterschiedlichen Text.Andernfalls würden Sie die Textunterschiede wahrscheinlich ziemlich schnellnichtmehrbemerken.I think it'd be better to use different CSS classes on the message, so that the messages could have different background colors in environments in addition to just having slightly different text. Otherwise I think you'd stop noticing the text differences pretty quickly.
- 1
- 2012-01-16
- Ian Dunn
-
- 2010-11-06
Sammlung von Quick Function.php-Änderungen
Ich habe auchein paartolle Verbesserungenin
functions.php
. Ich habe diemeisten davongefunden,indemichim Laufe der Jahrenachihnengesucht habe.Auszugsende
function new_excerpt_more($more) { return '...'; } add_filter('excerpt_more', 'new_excerpt_more');
WP Admin-Logoersetzen
function new_admin_logo() { echo '<style type="text/css">#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/admin_logo.png) !important; }</style>'; } add_action('admin_head', 'new_admin_logo');
Benutzerdefinierter Favicon WP-Admin
function admin_favicon() { echo '<link rel="shortcut icon" type="image/x-icon" href="' . get_bloginfo('template_directory') . '/images/favicon.ico" />'; } add_action( 'admin_head', 'admin_favicon' );
Benutzerdefinierte Admin-Fußzeile
function custom_admin_footer() { echo 'Welcome to my blog! No More Documentation Links!'; } add_filter('admin_footer_text', 'custom_admin_footer');
Collection of quick function.php edits
I have a few awesome tweaks in
functions.php
as well. Found most of these by searching for them over the years.Excerpt Ending
function new_excerpt_more($more) { return '...'; } add_filter('excerpt_more', 'new_excerpt_more');
Replace WP Admin Logo
function new_admin_logo() { echo '<style type="text/css">#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/admin_logo.png) !important; }</style>'; } add_action('admin_head', 'new_admin_logo');
Custom Favicon WP-Admin
function admin_favicon() { echo '<link rel="shortcut icon" type="image/x-icon" href="' . get_bloginfo('template_directory') . '/images/favicon.ico" />'; } add_action( 'admin_head', 'admin_favicon' );
Custom Admin Footer
function custom_admin_footer() { echo 'Welcome to my blog! No More Documentation Links!'; } add_filter('admin_footer_text', 'custom_admin_footer');
-
danke aber diese wurdenbereits hinzugefügt.thanks but these have already been added.
- 0
- 2010-11-08
- NetConstructor.com
-
Könnten Siebitte diese durchgehen und sicherstellen,dasses keine doppelten Einträgegibt,undjedenin dennächsten Wochenin eineeigene Antwort aufteilen?could you please go through these and ensure there are no duplicate entires and split each one up into its own answer within the next few weeks?
- 0
- 2011-01-26
- NetConstructor.com
-
- 2010-11-08
Behoben: Standard-Wordpress-Meta-Boxenentfernen
Dies war sehrpraktisch,hatte abereinige Fehler
// REMOVE META BOXES FROM DEFAULT POSTS SCREEN function remove_default_post_screen_metaboxes() { remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Metabox remove_meta_box( 'trackbacksdiv','post','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox remove_meta_box( 'authordiv','post','normal' ); // Author Metabox } add_action('admin_menu','remove_default_post_screen_metaboxes'); // REMOVE META BOXES FROM DEFAULT PAGES SCREEN function remove_default_page_screen_metaboxes() { global $post_type; remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox remove_meta_box('commentsdiv','page','normal'); // Comments remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox remove_meta_box( 'authordiv','page','normal' ); // Author Metabox } add_action('admin_menu','remove_default_page_screen_metaboxes');
Fixed: Remove Default Wordpress Meta Boxes
This was very handy but had some errors
// REMOVE META BOXES FROM DEFAULT POSTS SCREEN function remove_default_post_screen_metaboxes() { remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Metabox remove_meta_box( 'trackbacksdiv','post','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox remove_meta_box( 'authordiv','post','normal' ); // Author Metabox } add_action('admin_menu','remove_default_post_screen_metaboxes'); // REMOVE META BOXES FROM DEFAULT PAGES SCREEN function remove_default_page_screen_metaboxes() { global $post_type; remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox remove_meta_box('commentsdiv','page','normal'); // Comments remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox remove_meta_box( 'authordiv','page','normal' ); // Author Metabox } add_action('admin_menu','remove_default_page_screen_metaboxes');
-
- 2010-11-11
Verlängerung der automatischen Abmeldefrist
Getestet am: Wordpress 3.0.1
Mit demfolgenden Code können Sie die Aufbewahrungsdauer von Cookies verlängern. Daherbleiben angemeldete Benutzer länger angemeldet:
function keep_me_logged_in_for_1_year( $expirein ) { return 31556926; // 1 year in seconds } add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );
Extending Auto Logout Period
Tested on: Wordpress 3.0.1
Using the code below you can increase the time cookies are kept and therefor users who are logged in remain logged in longer:
function keep_me_logged_in_for_1_year( $expirein ) { return 31556926; // 1 year in seconds } add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );
-
Esgibt nocheinen anderen Trick,denich hiergefunden habe: http://wpengineer.com/2064/stop-wordpress-from-ever-logging-out/there is another trick which can be used which I found here: http://wpengineer.com/2064/stop-wordpress-from-ever-logging-out/
- 1
- 2010-11-11
- NetConstructor.com
-
Es solltebeachtet werden,dass das Sitzungszeitlimit aus Sicherheitsgründen vorhandenist. Wenn Siees alsoerweitern/entfernen,wird Ihre Site anfälliger.It should be noted that the session timeout is there as a security precaution, so extending/removing it makes your site more vulnerable.
- 3
- 2012-01-16
- Ian Dunn
-
- 2010-11-14
Fügen Sieeine "Einstellungen" hinzu. Linkfür Plugins auf der Plugin-Listenseite
"Einstellungeneinstellen" Linkfür Plugins auf der Plugin-Seiteim WordPress-Backend,einfach zu verwendender Sprung zu Einstellungenfür Benutzer (der Codeist auchmit einer Lösungfür die WordPress-Version kleiner 2.9enthalten)
// plugin definitions define( 'FB_BASENAME', plugin_basename( __FILE__ ) ); define( 'FB_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) ); define( 'FB_FILENAME', str_replace( FB_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) ); function filter_plugin_meta($links, $file) { /* create link */ if ( $file == FB_BASENAME ) { array_unshift( $links, sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_FILENAME, __('Settings') ) ); } return $links; } global $wp_version; if ( version_compare( $wp_version, '2.7alpha', '>' ) ) { add_filter( 'plugin_action_links_' . FB_WM_BASENAME, 'filter_plugin_meta', 10, 2); } else { add_filter( 'plugin_action_links', 'filter_plugin_meta', 10, 2 ); }
Add a "Settings" link for plugins on the plugin list page
Set "Settings" link for plugins on plugin-page in WordPress backend, easy to use jump to settings for users (the code is also with an solution for WordPress version smaller 2.9)
// plugin definitions define( 'FB_BASENAME', plugin_basename( __FILE__ ) ); define( 'FB_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) ); define( 'FB_FILENAME', str_replace( FB_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) ); function filter_plugin_meta($links, $file) { /* create link */ if ( $file == FB_BASENAME ) { array_unshift( $links, sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_FILENAME, __('Settings') ) ); } return $links; } global $wp_version; if ( version_compare( $wp_version, '2.7alpha', '>' ) ) { add_filter( 'plugin_action_links_' . FB_WM_BASENAME, 'filter_plugin_meta', 10, 2); } else { add_filter( 'plugin_action_links', 'filter_plugin_meta', 10, 2 ); }
-
Ich habe versucht,diesen Code zu verwenden,aberes scheint,dasser unter WordPress 3.1nichtfunktioniert.Können Siebestätigen und aktualisierenI have attempted to use this code but it seem that it does not work on wordpress 3.1. Can you confirm and update
- 0
- 2011-02-22
- NetConstructor.com
-
@ NetConstructor.com Ich habeein kleines Gebot voneinem meiner kostenlosen Plugins aktualisiert,auf allenmeinen Pluginsfunktioniert dieseinwandfrei@NetConstructor.com I have update a little bid from one of my free plugins, on all my plugins works fine this
- 0
- 2011-02-28
- bueltge
-
Ich wünschte,alle Plugin-Autoren würden diestun (natürlichfür die Pluginsmit Einstellungsseiten),sodass diese Art von Codenichterforderlich wäre.I wish all plugin authors would do this (for the plugins that have settings pages, of course) so this kind of code wouldn't be necessary.
- 0
- 2011-12-06
- JimmyPena
-
- 2010-12-28
Entfernen Sie die automatische Verknüpfung von URLsin WordPress-Kommentaren
remove_filter ('comment_text','make_clickable',9);
Remove Auto Linking of URLs in WordPress Comments
remove_filter('comment_text', 'make_clickable', 9);
-
Nett!Ich habenach dieser `make_clickable ()` Funktiongesucht,um sie auf`the_content` anzuwenden!Warum haben siees überhauptnichtgetan?Esist soeinfach wie das Hinzufügen von "add_filter" ("the_content","make_clickable"); "Alternativ kann dieserfolgen,wenn der Beitragmithilfeeines [anderen Hooks]gespeichert wird (http://stackoverflow.com/a/5036802/288906).Nice! I was looking for that `make_clickable()` function to apply it to `the_content`! Why didn't they do it in the first place? It's as simple as adding `add_filter( 'the_content', 'make_clickable');` Alternatively it could be done when the post is saved by using a [different hook](http://stackoverflow.com/a/5036802/288906)
- 0
- 2014-01-11
- fregante
-
- 2011-03-19
Seitenvorlagenfilter zur Seitenliste hinzufügen
Getestet am: WP 3.1
Fügt der Seitenlisteeinen Seitenvorlagenfilter hinzu,sodass Sieeine Liste der Seiten anzeigen können,an dieeine bestimmte Vorlage angehängtist.
class Page_Template_Filter { private $templates = array(); public function __construct() { // If it's not the admin area or the current user can't edit pages let's just bail here if( !is_admin() || !current_user_can('edit_pages') ) return; add_action( 'parse_query', array( $this, 'pt_parse_query' ) ); add_action( 'restrict_manage_posts', array( $this, 'pt_restrict_manage_posts' ) ); } public function pt_parse_query( $query ) { global $pagenow, $post_type; if( 'edit.php' != $pagenow ) return; switch( $post_type ) { case 'post': break; case 'page': $this->templates = get_page_templates(); if( empty( $this->templates ) ) return; if( !$this->is_set_template() ) return; $meta_group = array( 'key' => '_wp_page_template', 'value' => $this->get_template() ); set_query_var( 'meta_query', array( $meta_group ) ); break; } } public function pt_restrict_manage_posts() { if( empty( $this->templates ) ) return; $this->template_dropdown(); } private function get_template() { if( $this->is_set_template() ) foreach( $this->templates as $template ) { if( $template != $_GET['page_template'] ) continue; return $template; } return ''; } private function is_set_template() { return (bool) ( isset( $_GET['page_template'] ) && ( in_array( $_GET['page_template'], $this->templates ) ) ); } private function template_dropdown() { ?> <select name="page_template" id="page_template"> <option value=""> - no template - </option> <?php foreach( $this->templates as $name => $file ): ?> <option value="<?php echo $file; ?>"<?php selected( $this->get_template() == $file ); ?>><?php _e( $name ); ?></option> <?php endforeach;?> </select> <?php } } add_action('admin_init', 'load_ptf'); function load_ptf() { $Page_Template_Filter = new Page_Template_Filter; }
Zum Arbeitenistmindestens 3.1erforderlich,obwohl die
meta_query
durch die älterenmeta_key
undmeta_value
für 3.0ersetzt werden könnte.Add page template filter to page listing
Tested on: WP 3.1
Adds a page template filter to the page listing, so you can view a list of pages that have a given template attached.
class Page_Template_Filter { private $templates = array(); public function __construct() { // If it's not the admin area or the current user can't edit pages let's just bail here if( !is_admin() || !current_user_can('edit_pages') ) return; add_action( 'parse_query', array( $this, 'pt_parse_query' ) ); add_action( 'restrict_manage_posts', array( $this, 'pt_restrict_manage_posts' ) ); } public function pt_parse_query( $query ) { global $pagenow, $post_type; if( 'edit.php' != $pagenow ) return; switch( $post_type ) { case 'post': break; case 'page': $this->templates = get_page_templates(); if( empty( $this->templates ) ) return; if( !$this->is_set_template() ) return; $meta_group = array( 'key' => '_wp_page_template', 'value' => $this->get_template() ); set_query_var( 'meta_query', array( $meta_group ) ); break; } } public function pt_restrict_manage_posts() { if( empty( $this->templates ) ) return; $this->template_dropdown(); } private function get_template() { if( $this->is_set_template() ) foreach( $this->templates as $template ) { if( $template != $_GET['page_template'] ) continue; return $template; } return ''; } private function is_set_template() { return (bool) ( isset( $_GET['page_template'] ) && ( in_array( $_GET['page_template'], $this->templates ) ) ); } private function template_dropdown() { ?> <select name="page_template" id="page_template"> <option value=""> - no template - </option> <?php foreach( $this->templates as $name => $file ): ?> <option value="<?php echo $file; ?>"<?php selected( $this->get_template() == $file ); ?>><?php _e( $name ); ?></option> <?php endforeach;?> </select> <?php } } add_action('admin_init', 'load_ptf'); function load_ptf() { $Page_Template_Filter = new Page_Template_Filter; }
Requires at least 3.1 to work, though the
meta_query
could be replaced with the oldermeta_key
andmeta_value
for 3.0.-
funktionierteinwandfrei,getestetin 3.4-alphaworks flawlessly, tested in 3.4-alpha
- 0
- 2012-04-02
- brasofilo
-
- 2010-09-13
Entfernen Sie XML-RPC,wennesnicht zur Leistungssteigerung verwendet wird.
Getestet am: Wordpress 3.0.1
WordPress verwendeteine CURL-Operation,um die SSL-Fähigkeitfür XML-RPC zutesten.Wenn Sie XML-RPC verwenden,abernicht verwenden,können Sie den Filterentfernen.Diesisteine kleine Leistungssteigerung (da WPim Grundegenommenein cURL GETfür die https-URL ausführt undentweder 1)eine abgelehnte Nachrichterhält oder 2)eine Zeitüberschreitung auftritt undesbis zu 5 Sekunden dauern kann),aberin unserem Fall wird diestatsächlich verhindertEin Gateway-Timeout,bei demein Zeitlimitfüreinen Proxy abgelaufenist,bevor das cURL-GET abgelaufenist,wodurch XML-RPC unbrauchbar wird.
// Prevents WordPress from testing ssl capability on domain.com/xmlrpc.php?rsd remove_filter('atom_service_url','atom_service_url_filter');
Remove XML-RPC when not in use for performance boost
Tested on: Wordpress 3.0.1
WordPress uses a CURL operation to test for SSL capability for XML-RPC. If you're using XML-RPC but not using, then you can remove the filter. This is a small performance boost (since basically WP does a cURL GET on the https url and either 1) gets a denied message, or 2) times out, and it can take upwards of 5 seconds), but in our case it actually prevented a gateway timeout where a proxy was timing out before the cURL GET was timing out rendering XML-RPC unusable.
// Prevents WordPress from testing ssl capability on domain.com/xmlrpc.php?rsd remove_filter('atom_service_url','atom_service_url_filter');
-
Vielen Dankfür den Code-Vorschlag.Eine Frage: Wenn Sie XML-RPC verwenden,abernicht die SSL-Funktionen verwenden,würde das Einbeziehen dieses Codes die Dinge überhauptbeschleunigen?Wennnicht,in welchen Situationen würde die Aufnahme dieses Codes von Vorteil sein?Thanks for the code suggestion. One question, if you are using XML-RPC but not using the SSL capabilities would the including of this code speed things up at all? If not, in what situations would the inclusion of this code serve a benefit?
- 0
- 2010-09-14
- NetConstructor.com
-
Dies wirkt sichnurgeringfügig auf die Leistung von XML-RPC-Aufrufen aus,da diesenichtmehr übereine HTTP-Anforderung auf SSL-Fähigkeitprüfenmüssen.It has a minuscule effect on performance for XML-RPC calls, since they no longer have to check for SSL capability via an HTTP request.
- 0
- 2010-09-19
- gabrielk
-
- 2010-11-15
Allebenutzerdefinierten Felderglobal abrufen
function get_custom_field($key, $echo = FALSE) { global $post; $custom_field = get_post_meta( $post->ID, $key, true ); if ( $echo == false ) return $custom_field; echo $custom_field; }
Rufen Sie dann das Feldmit einereinzelnen Zeile
auf<?php get_custom_field('custom-field-name', TRUE); ?>
Grab all custom fields globally
function get_custom_field($key, $echo = FALSE) { global $post; $custom_field = get_post_meta( $post->ID, $key, true ); if ( $echo == false ) return $custom_field; echo $custom_field; }
Then call the field with a single line
<?php get_custom_field('custom-field-name', TRUE); ?>
-
Warum solltejemand dasbenutzen?Wasist der Vorteil?Why would someone use this? What's the benefit?
- 0
- 2010-12-05
- matt
-
Für Websites/Themen,die vielebenutzerdefinierte Felder verwenden (dieich häufigfür die Client-Arbeit verwende),ist weniger Codeim Thema zulässig,undes können Bedingungen hinzugefügt werden,ob das Feld überhaupt angezeigt werden soll odernicht.for sites / themes that use a lot of custom fields (which I use often for client work) it allows for less code in the theme, and also for adding conditionals on whether or not to display the field at all.
- 2
- 2010-12-10
- Norcross
-
- 2010-11-17
Gibt die Anzahl der Kommentare zurück
Diesentspricht
count_user_posts()
,gibt jedoch stattdessen die Anzahl der Kommentare zurück:function count_user_comments($id) { global $wpdb; $users = $wpdb->get_var(" SELECT COUNT( * ) AS total FROM $wpdb->comments WHERE comment_approved = 1 AND user_id = $id"); return $users; }
Mehr: Anzahl der Beiträge des Benutzers (einschließlichbenutzerdefinierter Beitragstypen) oder Kommentare:
function atom_count($user_id, $what_to_count = 'post') { global $wpdb; $where = $what_to_count == 'comment' ? "WHERE comment_approved = 1 AND user_id = {$user_id}" : get_posts_by_author_sql($what_to_count, TRUE, $user_id); $from = "FROM ".(($what_to_count == 'comment') ? $wpdb->comments : $wpdb->posts); $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) {$from} {$where}")); return $count; }
Verwendungsbeispiele:
<?php echo atom_count(1, 'movie'); // displays 'movie' post type count ?>
<?php echo atom_count(1, 'comment'); // displays comment count ?>
Return the number of comments
This is like
count_user_posts()
, but returns the number of comments instead:function count_user_comments($id) { global $wpdb; $users = $wpdb->get_var(" SELECT COUNT( * ) AS total FROM $wpdb->comments WHERE comment_approved = 1 AND user_id = $id"); return $users; }
More: Count User's posts (including custom post types) or comments:
function atom_count($user_id, $what_to_count = 'post') { global $wpdb; $where = $what_to_count == 'comment' ? "WHERE comment_approved = 1 AND user_id = {$user_id}" : get_posts_by_author_sql($what_to_count, TRUE, $user_id); $from = "FROM ".(($what_to_count == 'comment') ? $wpdb->comments : $wpdb->posts); $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) {$from} {$where}")); return $count; }
Usage examples:
<?php echo atom_count(1, 'movie'); // displays 'movie' post type count ?>
<?php echo atom_count(1, 'comment'); // displays comment count ?>
-
- 2010-12-28
Aktivieren Sie oEmbedin Text-/HTML-Widgets
add_filter ('widget_text',Array ($ wp_embed,'run_shortcode'),8); add_filter ('widget_text',Array ($ wp_embed,'autoembed'),8);
Ich verwende diesfür YouTube-Video-Widgets und Flickr-Inhalte.
Enable oEmbed in Text/HTML Widgets
add_filter( 'widget_text', array( $wp_embed, 'run_shortcode' ), 8 ); add_filter( 'widget_text', array( $wp_embed, 'autoembed'), 8 );
I use this for youtube video widgets and flickr stuff.
-
- 2010-09-15
Post Word Count
Getestet am: Wordpress 3.0.1
(Ursprünglich aus dem Plug-in "Post Word Count" von Nick Momrick )
Fügteine Anzahl derinsgesamt veröffentlichten Wörter am unteren Rand des & quot; Im Moment & quot; Feldim Admin-Dashboard. Nützlich,wenn Sie Ihr Blog als Ausgangsbasisfüretwas wie NaNoWriMo verwenden odereinfachnur den Überblickbehaltenmöchten wieproduktiv Ihre Blogging-Fähigkeitengeworden sind.
function post_word_count() { $count = 0; $posts = get_posts( array( 'numberposts' => -1, 'post_type' => array( 'post', 'page' ) )); foreach( $posts as $post ) { $count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID ))); } $num = number_format_i18n( $count ); // This block will add your word count to the stats portion of the Right Now box $text = _n( 'Word', 'Words', $num ); echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>"; // This line will add your word count to the bottom of the Right Now box. echo '<p>This blog contains a total of <strong>' . $num . '</strong> published words!</p>'; } // add to Content Stats table add_action( 'right_now_content_table_end', 'post_word_count'); // add to bottom of Activity Box add_action('activity_box_end', 'post_word_count');
Eingroßes Lob an Rarst für die abfragefreie Bereinigung des Codes!
Post Word Count
Tested on: Wordpress 3.0.1
(Originally extracted from the Post Word Count plug-in by Nick Momrick)
Adds a count of total published words to the bottom of the "Right Now" box on the admin dashboard. Useful if you're using your blog as an outlet for something like NaNoWriMo or if you just want to keep track of how prolific your blogging skills have become.
function post_word_count() { $count = 0; $posts = get_posts( array( 'numberposts' => -1, 'post_type' => array( 'post', 'page' ) )); foreach( $posts as $post ) { $count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID ))); } $num = number_format_i18n( $count ); // This block will add your word count to the stats portion of the Right Now box $text = _n( 'Word', 'Words', $num ); echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>"; // This line will add your word count to the bottom of the Right Now box. echo '<p>This blog contains a total of <strong>' . $num . '</strong> published words!</p>'; } // add to Content Stats table add_action( 'right_now_content_table_end', 'post_word_count'); // add to bottom of Activity Box add_action('activity_box_end', 'post_word_count');
Kudos to Rarst for the query-free cleanup of the code!
-
Dankefür die Unterstützung,* Rarst *.Normalerweisemagichesnicht,direkte Datenbankabfragenin den Plug-In-Code "function.php" aufzunehmen,aber wiegesagt,er wurde ursprünglich aus dem Plug-Ineines anderen übernommen.Thanks for the assist, *Rarst*. I typically don't like to include direct database queries in plug-in `function.php` code, but like I said it was originally taken from someone else's plug-in.
- 0
- 2010-09-15
- EAMann
-
np,ich habees vor langer Zeit versucht undes warein Durcheinander.:) Jetztmit verbesserten Fähigkeiten wares Zeit,es richtig zumachen.Warum alten Ausgangsteil verlassen?Ich denke,esist sinnvoll,esmit den restlichen Statistiken anzuzeigen.Übrigensgibt diese Versioneine andere Summe an (im Vergleich zu "explodieren"). Dies liegt wahrscheinlich an Filtern auf dem Weg und dergleichenbeim Abrufen über die API.np, I tried this long time ago and it was a mess. :) Now with upgraded skills it was time to do it right. Why left old output part? I think it makes sense to display it with rest of stats. btw this version gives different total (comparing to `explode`), this is probably because of filters along the way and such when fetching via API.
- 0
- 2010-09-15
- Rarst
-
Der Unterschiedin der Anzahl der Beiträgeistein Ergebnis von Filtern ... aber die Verwendung von "get_posts ()" wird wahrscheinlich sowiesoeine genauere Wortzahl sein.Ich habe die alte Ausgabezeileeinfach verlassen,weilich sie so verwendet habe ...mehreine Meinungsverschiedenheit als alles andere ... Ich werde Ihr Beispielerneut hinzufügen,umes den Statistiken hinzuzufügen,damit die Leutees auswählen können.The difference in post count is a result of filters ... but using `get_posts()` will likely be a more accurate word count anyway. I left the old output line simply because that's how I've been using it ... more a difference of opinion than anything else ... I'll re-add your example to add it to the stats so people can pick.
- 0
- 2010-09-15
- EAMann
-
- 2010-09-17
Spezifischen Inhaltnurfür angemeldete Benutzer anzeigen
Getestet am: Wordpress 3.0.1
function content_only4logged_in($content) { // ALL LOGGED IN USERS if ( is_user_logged_in() && !is_null($content) && !is_feed() ) { return $content; } else { $content = wp_html_excerpt( $content, 80 ); $content .= ' …'; $content .= __( 'Sorry, more of this content is only available for logged users.', FB_TEXTDOMAIN ); return $content; } } add_action( 'the_content', 'content_only4logged_in' );
Weitere Möglichkeiten und Informationenfinden Sieim Beitrag http://wpengineer.com/2046/control-the-wordpress-content-via-userrights-or-time/
Display Specific Content only for logged in users
Tested on: Wordpress 3.0.1
function content_only4logged_in($content) { // ALL LOGGED IN USERS if ( is_user_logged_in() && !is_null($content) && !is_feed() ) { return $content; } else { $content = wp_html_excerpt( $content, 80 ); $content .= ' …'; $content .= __( 'Sorry, more of this content is only available for logged users.', FB_TEXTDOMAIN ); return $content; } } add_action( 'the_content', 'content_only4logged_in' );
more possibilities and informations on the post http://wpengineer.com/2046/control-the-wordpress-content-via-userrights-or-time/
-
Ich kann diesnicht dazubringen,geänderten Inhaltfürnicht angemeldete Benutzer anzuzeigen ... dererste Teilfunktionierteinwandfrei,aber wenn der Benutzernicht angemeldetist und die Seite alsprivatmarkiertist,wirdmirnur die reguläre 404 zugestellt?I can't get this to display altered content for non-logged in users... the first part works fine, but it the user is not logged in and the page is marked private, I just get served the regular 404?
- 0
- 2011-02-09
- gillespieza
-
- 2010-09-30
Skriptebedingt laden
Hier können Sie Skriptenur laden,wennein bestimmter Shortcode oderein bestimmtes Widget vorhandenist. Quelle: Skripte werdennurgeladen,wennein bestimmter Shortcode oderein bestimmtes Widget vorhandenist
function has_my_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( stripos($post->post_content, '[my_shortcode') ) $found = true; break; } if ($found){ $urljs = get_bloginfo( 'template_directory' ).IMP_JS; wp_register_script('my_script', $urljs.'myscript.js' ); wp_print_scripts('my_script'); } return $posts; } add_action('the_posts', 'has_my_shortcode');
Und hiererfahren Sie,wie Sie Skriptenur laden,wennein bestimmtes Widget vorhandenist
Um das Skript auf der Seite zu laden,auf dernur das Widgetgeladenist,müssen Sie den Codeis_active_widget ()in Ihre Widget-Klasseeinfügen. Siehebeispielsweise das Standard-Widgetfür aktuelle Kommentare (wp-includes/default-widgets.php,Zeile 602):
class WP_Widget_Recent_Comments extends WP_Widget { function WP_Widget_Recent_Comments() { $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) ); $this->WP_Widget('recent-comments', __('Recent Comments'), $widget_ops); $this->alt_option_name = 'widget_recent_comments'; if ( is_active_widget(false, false, $this->id_base) ) add_action( 'wp_head', array(&$this, 'recent_comments_style') ); add_action( 'comment_post', array(&$this, 'flush_widget_cache') ); add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') ); }
Loading scripts conditionally
Here is a way to load scripts only if a particular shortcode or widget is present. source: Loading scripts only if a particular shortcode or widget is present
function has_my_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( stripos($post->post_content, '[my_shortcode') ) $found = true; break; } if ($found){ $urljs = get_bloginfo( 'template_directory' ).IMP_JS; wp_register_script('my_script', $urljs.'myscript.js' ); wp_print_scripts('my_script'); } return $posts; } add_action('the_posts', 'has_my_shortcode');
And here is how to load scripts only if a certain widget is present
To load the script in the page where the widget is loaded only, you will have to add the is_active_widget() code, in you widget class. E.g., see the default recent comments widget (wp-includes/default-widgets.php, line 602):
class WP_Widget_Recent_Comments extends WP_Widget { function WP_Widget_Recent_Comments() { $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) ); $this->WP_Widget('recent-comments', __('Recent Comments'), $widget_ops); $this->alt_option_name = 'widget_recent_comments'; if ( is_active_widget(false, false, $this->id_base) ) add_action( 'wp_head', array(&$this, 'recent_comments_style') ); add_action( 'comment_post', array(&$this, 'flush_widget_cache') ); add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') ); }
-
- 2010-11-10
Benutzerdefiniertes Dashboard-CSS
/* Change WordPress dashboard CSS */ function custom_admin_styles() { echo '<style type="text/css">#wphead{background:#069}</style>'; } add_action('admin_head', 'custom_admin_styles');
Sie können zwischen den Tags Änderungen am CSS hinzufügen.
Custom Dashboard CSS
/* Change WordPress dashboard CSS */ function custom_admin_styles() { echo '<style type="text/css">#wphead{background:#069}</style>'; } add_action('admin_head', 'custom_admin_styles');
You can add any changes to the css between the tags.
-
- 2010-12-03
Privates undgeschütztes Präfixentfernen
Diese Funktionentfernt das & quot; Privite: & quot;Präfix von Posts und Seiten,die alsprivatmarkiert sind.Nützlichfür Inhalte,dienurfür angemeldete Benutzer oder Gruppen sichtbar sind.
function the_title_trim($title) { $title = attribute_escape($title); $findthese = array( '#Protected:#', '#Private:#' ); $replacewith = array( '', // What to replace "Protected:" with '' // What to replace "Private:" with ); $title = preg_replace($findthese, $replacewith, $title); return $title; } add_filter('the_title', 'the_title_trim');
BEARBEITEN: Aktualisiert,um auch das Entfernen von "Geschützt:"einzuschließen.
Remove Private and Protected Prefix
This function removes the "Privite:" prefix from posts and pages marked private. Useful for content only visible to logged in users or groups.
function the_title_trim($title) { $title = attribute_escape($title); $findthese = array( '#Protected:#', '#Private:#' ); $replacewith = array( '', // What to replace "Protected:" with '' // What to replace "Private:" with ); $title = preg_replace($findthese, $replacewith, $title); return $title; } add_filter('the_title', 'the_title_trim');
EDIT: Updated to include the removal of Protected: as well.
-
- 2011-01-02
Benutzerdefinierte Auszugslänge
function excerpt($num) { $limit = $num+1; $excerpt = explode(' ', get_the_excerpt(), $limit); array_pop($excerpt); $excerpt = implode(" ",$excerpt)."... (<a href='" .get_permalink($post->ID) ." '>Read more</a>)"; echo $excerpt; }
Begrenzen Sie die Länge des angezeigten Auszugs,indem Siein das Thema schreiben: Auszug ('20 ');
Beispiel:
<?php excerpt('22'); ?>
Dadurch wird der Auszug auf 22 Zeichenbegrenzt.Der Auszug wirdmit
unterbrochen... (Read More)
Custom excerpt length
function excerpt($num) { $limit = $num+1; $excerpt = explode(' ', get_the_excerpt(), $limit); array_pop($excerpt); $excerpt = implode(" ",$excerpt)."... (<a href='" .get_permalink($post->ID) ." '>Read more</a>)"; echo $excerpt; }
Limit the length of the displayed excerpt by writing in the theme: excerpt('20');
Example:
<?php excerpt('22'); ?>
This will limit the excerpt to 22 characters.The excerpt will be interupted with
... (Read More)
-
- 2011-02-21
Hinzufügeneines übergeordneten Seiten-Slugs zubody_class
/*************************************************************** * Function body_class_section * Add the top level page to the body class for coloured sections ***************************************************************/ add_filter('body_class','body_class_section'); function body_class_section($classes) { global $wpdb, $post; if (is_page()) { if ($post->post_parent) { $parent = end(get_post_ancestors($current_page_id)); } else { $parent = $post->ID; } $post_data = get_post($parent, ARRAY_A); $classes[] = 'section-' . $post_data['post_name']; } return $classes; }
Dieser Filterfügteine eindeutige Körperklasse hinzu,die auf dem übergeordneten übergeordneten Element der aktuellen Seitebasiert. Ich verwende diesfür Websites,diefürjeden Abschnitt der Websitebestimmte Farben oder Layouts haben. Esfunktioniert ambestenmit Websites,die auf Seitenbasieren. CSS-Beispiele:
.section-about { background: red; } .section-portfolio { background: blue; }
Ihr Themamuss auch die Funktion body_class verwenden.
Fix oEmbed Flash-Objekte
/*************************************************************** * Function my_oembed_wmode * Fix oEmbed window mode for flash objects ***************************************************************/ add_filter('embed_oembed_html', 'my_oembed_wmode', 1); function my_oembed_wmode( $embed ) { if ( strpos( $embed, '<param' ) !== false ) { $embed = str_replace( '<embed', '<embed wmode="transparent" ', $embed ); $embed = preg_replace( '/param>/', 'param><param name="wmode" value="transparent" />', $embed, 1); } return $embed; }
Ich hattein der Vergangenheit Probleme,bei deneneingebettete Flash-Objektemit Dropdown-Navigationsmenüs kollidieren. Dieser Filterbehebt dieses Problem,indem den Einbettungenein transparenter Fenstermodus hinzugefügt wird.
Entfernen Sie die Spalte "Kommentare" aus der Liste der Admin-Seiten
/*************************************************************** * Function custom_pages_columns * Remove "comments" from pages overview (rarely use comments on pages) ***************************************************************/ add_filter('manage_pages_columns', 'custom_pages_columns'); function custom_pages_columns($defaults) { unset($defaults['comments']); return $defaults; }
Ichbenutze kaum Kommentare zu Seiten und dies hilft,die Dingeim WordPress-Dashboard aufgeräumt zu halten.
Add parent page slug to body_class
/*************************************************************** * Function body_class_section * Add the top level page to the body class for coloured sections ***************************************************************/ add_filter('body_class','body_class_section'); function body_class_section($classes) { global $wpdb, $post; if (is_page()) { if ($post->post_parent) { $parent = end(get_post_ancestors($current_page_id)); } else { $parent = $post->ID; } $post_data = get_post($parent, ARRAY_A); $classes[] = 'section-' . $post_data['post_name']; } return $classes; }
This filter adds a unique body class based on the highest level parent of the current page. I use this for sites that have specific colours or layouts for each section of the site. It works best with sites based around pages. CSS examples:
.section-about { background: red; } .section-portfolio { background: blue; }
Your theme must also make use of the body_class function.
Fix oEmbed flash objects
/*************************************************************** * Function my_oembed_wmode * Fix oEmbed window mode for flash objects ***************************************************************/ add_filter('embed_oembed_html', 'my_oembed_wmode', 1); function my_oembed_wmode( $embed ) { if ( strpos( $embed, '<param' ) !== false ) { $embed = str_replace( '<embed', '<embed wmode="transparent" ', $embed ); $embed = preg_replace( '/param>/', 'param><param name="wmode" value="transparent" />', $embed, 1); } return $embed; }
I have had problems in the past where oEmbed Flash objects collide with drop down navigation menus. This filter fixes that problem by adding a transparent window mode to the embeds.
Remove the "comments" column from Admin page list
/*************************************************************** * Function custom_pages_columns * Remove "comments" from pages overview (rarely use comments on pages) ***************************************************************/ add_filter('manage_pages_columns', 'custom_pages_columns'); function custom_pages_columns($defaults) { unset($defaults['comments']); return $defaults; }
I hardly ever make use of commenting on pages and this helps keep things tidy in the WordPress dashboard.
-
- 2010-09-10
Numerische Paginierung aktivieren
Getestet am: Wordpress 3.0.1
/* Numeric Pagination ********************************************/ function numeric_pagination ($pageCount = 9, $query = null) { if ($query == null) { global $wp_query; $query = $wp_query; } if ($query->max_num_pages <= 1) { return; } $pageStart = 1; $paged = $query->query_vars['paged']; // set current page if on the first page if ($paged == null) { $paged = 1; } // work out if page start is halfway through the current visible pages and if so move it accordingly if ($paged > floor($pageCount / 2)) { $pageStart = $paged - floor($pageCount / 2); } if ($pageStart < 1) { $pageStart = 1; } // make sure page start is if ($pageStart + $pageCount > $query->max_num_pages) { $pageCount = $query->max_num_pages - $pageStart; } ?> <div id="archive_pagination"> <?php if ($paged != 1) { ?> <a href="<?php echo get_pagenum_link(1); ?>" class="numbered page-number-first"><span>‹ <?php _e('<< First', 'global'); ?></span></a> <?php } // first page is not visible... if ($pageStart > 1) { //echo 'previous'; } for ($p = $pageStart; $p <= $pageStart + $pageCount; $p ++) { if ($p == $paged) { ?> <span class="numbered page-number-<?php echo $p; ?> current-numeric-page"><?php echo $p; ?></span> <?php } else { ?> <a href="<?php echo get_pagenum_link($p); ?>" class="numbered page-number-<?php echo $p; ?>"><span><?php echo $p; ?></span></a> <?php } } // last page is not visible if ($pageStart + $pageCount < $query->max_num_pages) { //echo "last"; } if ($paged != $query->max_num_pages) { ?> <a href="<?php echo get_pagenum_link($query->max_num_pages); ?>" class="numbered page-number-last"><span><?php _e('>> Last', 'global'); ?> ›</span></a> <?php } ?> </div>
Enable Numeric Pagination
Tested on: Wordpress 3.0.1
/* Numeric Pagination ********************************************/ function numeric_pagination ($pageCount = 9, $query = null) { if ($query == null) { global $wp_query; $query = $wp_query; } if ($query->max_num_pages <= 1) { return; } $pageStart = 1; $paged = $query->query_vars['paged']; // set current page if on the first page if ($paged == null) { $paged = 1; } // work out if page start is halfway through the current visible pages and if so move it accordingly if ($paged > floor($pageCount / 2)) { $pageStart = $paged - floor($pageCount / 2); } if ($pageStart < 1) { $pageStart = 1; } // make sure page start is if ($pageStart + $pageCount > $query->max_num_pages) { $pageCount = $query->max_num_pages - $pageStart; } ?> <div id="archive_pagination"> <?php if ($paged != 1) { ?> <a href="<?php echo get_pagenum_link(1); ?>" class="numbered page-number-first"><span>‹ <?php _e('<< First', 'global'); ?></span></a> <?php } // first page is not visible... if ($pageStart > 1) { //echo 'previous'; } for ($p = $pageStart; $p <= $pageStart + $pageCount; $p ++) { if ($p == $paged) { ?> <span class="numbered page-number-<?php echo $p; ?> current-numeric-page"><?php echo $p; ?></span> <?php } else { ?> <a href="<?php echo get_pagenum_link($p); ?>" class="numbered page-number-<?php echo $p; ?>"><span><?php echo $p; ?></span></a> <?php } } // last page is not visible if ($pageStart + $pageCount < $query->max_num_pages) { //echo "last"; } if ($paged != $query->max_num_pages) { ?> <a href="<?php echo get_pagenum_link($query->max_num_pages); ?>" class="numbered page-number-last"><span><?php _e('>> Last', 'global'); ?> ›</span></a> <?php } ?> </div>
-
In WordPressgibt esbereitseine Funktion zum Ausführen dernumerischen Paginierung,siehe http://codex.wordpress.org/Function_Reference/paginate_linksThere's a function in WordPress for doing numeric pagination already, see http://codex.wordpress.org/Function_Reference/paginate_links
- 11
- 2010-11-11
- t31os
-
- 2010-09-28
Machen Sie Ihre Shortlinks kürzer,indem Sie das WWWentfernen
Getestet am: Wordpress 3.0.1
Machen Sie Ihre Shortlinks kürzer,wenn Sie
www.
in Ihre Domain aufnehmen.Über Scratch99.com :add_filter('get_shortlink','sjc_alter_shortlink'); function sjc_alter_shortlink($shortlink) { $shortlink = preg_replace('/^(https?:\/\/)?(www\.)/','$1',$shortlink); return $shortlink; }
Make your Shortlinks Shorter by Removing WWW
Tested on: Wordpress 3.0.1
Make your shortlinks shorter if you include
www.
in your domain. Via scratch99.com:add_filter('get_shortlink','sjc_alter_shortlink'); function sjc_alter_shortlink($shortlink) { $shortlink = preg_replace('/^(https?:\/\/)?(www\.)/','$1',$shortlink); return $shortlink; }
-
Eine Überprüfung sollte hinzugefügt werden,um sicherzustellen,dass die Zeichenfolge "www".wirdnurentfernt,wennesganz am Anfang des Domain-Teils der ursprünglichen URLgefunden wird.Dasnaive Ersetzen aneinerbeliebigen Stellein der URLführt zu Fehlern,wennesin einer Domain wie owww.com verwendet wurde (auf dertatsächlich WordPress ausgeführt wird) :)A check should be added to make sure the string "www." is only removed if it is found at the very beginning of the domain part of the original URL. Naively replacing it anywhere in the URL will lead to bugs if it had been used on a domain like owww.com (which actually appears to be running WordPress) :)
- 3
- 2012-05-28
- Ingve
-
@Ingve Ich habeesbehoben,jetzt wirdnur das anfängliche wwwentfernt@Ingve I fixed it, now it will remove only the initial www
- 0
- 2014-01-11
- fregante
-
- 2010-11-04
Überprüfen Sie,obein Beitrageingebetteten Inhaltenthält.
Überprüfen Sie,obein Beitrageingebetteten Inhaltenthält,innerhalb der Schleifemit der ID des aktuellen Beitrags arbeitet oder alternativeine ID übergeben werden kann,um den Beitrag zubestimmen,der aufeingebetteten Inhalt überprüft werden soll.
function has_embed( $post_id = false ) { if( !$post_id ) $post_id = get_the_ID(); else $post_id = absint( $post_id ); if( !$post_id ) return false; $post_meta = get_post_custom_keys( $post_id ); $post_meta = array_map( 'trim' , $post_meta ); foreach( $post_meta as $meta ) { if( '_oembed' != substr( $meta , 0 , 7 ) ) continue; return true; } return false; }
Sie würden die Funktiongenauso verwenden,wie Sieprüfen,obein Beitragein Tag hat.
if( has_embed() ) { // do whatever }
Funktiongibt true zurück,wenneine Einbettunggefunden wird,falsebei Fehler.
Check if a post has embedded content.
Check if a post has embedded content, works inside the loop using the current post's ID, or alternatively can be passed an ID to determine the post to check for embedded content.
function has_embed( $post_id = false ) { if( !$post_id ) $post_id = get_the_ID(); else $post_id = absint( $post_id ); if( !$post_id ) return false; $post_meta = get_post_custom_keys( $post_id ); $post_meta = array_map( 'trim' , $post_meta ); foreach( $post_meta as $meta ) { if( '_oembed' != substr( $meta , 0 , 7 ) ) continue; return true; } return false; }
You'd use the function in the same way you check if a post has a tag..
if( has_embed() ) { // do whatever }
Function returns true if an embed is found, false on fail.
-
Interessant,aberichfragemich,warum sollten Siees verwenden?Welche Art von Anwendungen hates?Interesting, but I'm wondering, why would you use it? What kind of applications does it have?
- 0
- 2010-12-05
- matt
-
Zu überprüfen,obein Beitrag aufeiner Seiteeingebettet ist,auf der Auszüge angezeigt werden,wäreeine Verwendung (undesist der ursprüngliche Anwendungsfall,für denichihngeschrieben habe).Anderemögliche Anwendungsfälle wären Benutzer,dieihreeigenen Themenvorlagen schreiben und Funktionenbereitstellenmöchten,die davon abhängen,obein Beitrag (oder Typ)eingebetteten Inhaltenthält,ohne dassein Filterfür "the_content" oder zahlreiche "get_post_custom_keys" -Aufrufeerforderlichist.Checking if a post has an embed on a page that displays excerpts would be one use(and it's the original use case i wrote it for). Other possible use cases would be with users who write their own theme templates and want to provide functionality dependant on whether a post(or type) has embedded content, without the need for a filter on `the_content` or numerous `get_post_custom_keys` calls.
- 0
- 2010-12-05
- t31os
-
- 2010-11-14
Beiträge von verschiedenenbenutzerdefinierten Beitragstypen auf der Startseite anzeigen
Wenn Sie denfolgenden Code am Ende dieses Beitragsin Ihre Dateifunctions.phpeinfügen,können Sie WordPress dazubringen,automatisch Beiträge von verschiedenenbenutzerdefinierten Beitragstypen anzuzeigen,die Sieerstellt haben. Derzeit zeigt WordPress standardmäßignur Beiträge an,die zu den Standard- "Beiträgen"gehören. Beitragstyp.
Imfolgenden Beispielmüssen Sie den Abschnitt ändern,der Folgendes aufruft:
$query->set( 'post_type', array('post', 'page', 'services', 'attachment'));
Mit Ihreneigenen benutzerdefinierten Beitragstypen,die Siein die Ergebnisse der Homepage-Beitragsliste aufnehmenmöchten. In diesem Fallbitten wir WordPress,uns alle Beiträge zurückzugeben,die zum Standard- "Beitrag"gehören. und & quot; Seite & quot;post_typefordert WordPress dann auf,auch denbenutzerdefinierten Beitragstyp anzugeben,den wirfür "Dienste"erstellt haben. und schließlich der Standard-WordPress-Post-Typ "Anhang". Diesbedeutet lediglich,dassjedes Mal,wennetwas zur Medienbibliothek hinzugefügt wird,es automatisch als separater Eintrag auf der Startseite angezeigt wird.
// CUSTOM HOMEPAGE POST LIST INCLUDING DIFFERENT POST_TYPES // make sure to edit the post types you wanted included in the list below add_filter( 'pre_get_posts', 'my_homepage_post_list' ); function my_homepage_post_list ( $query ) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array('post', 'page', 'services', 'attachment')); return $query; }
Sie können diesebenutzerdefinierte Abfrage auch an verschiedenen Speicherorten verwenden,z. B.in einembenutzerdefinierten Feed über soetwas
if (( is_home() && false == $query->query_vars['suppress_filters'] ) || is_feed())
Display Posts from Different Custom Post Types on homepage
By dropping the following code on the bottom of this post into your functions.php file you can get wordpress to automatically display posts from different custom post types you have created. Currently by default wordpress only display posts which belong to the default "posts" post type.
In the example provided below you will need to change the section which calls:
$query->set( 'post_type', array('post', 'page', 'services', 'attachment'));
With your own custom post types which you would like to include in the homepage post list results. In this case we are asking wordpress to return to us all posts belonging to the default "post" and "page" post_type then asking wordpress to also include the custom post type we created for "services" and finally the default wordpress post type of "attachment" which just means that anytime something is added to the media library it will automatically get displayed on the homepage as a separate entry.
// CUSTOM HOMEPAGE POST LIST INCLUDING DIFFERENT POST_TYPES // make sure to edit the post types you wanted included in the list below add_filter( 'pre_get_posts', 'my_homepage_post_list' ); function my_homepage_post_list ( $query ) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array('post', 'page', 'services', 'attachment')); return $query; }
You can also utilize this custom query in different locations, such as in a custom feed through something like this
if (( is_home() && false == $query->query_vars['suppress_filters'] ) || is_feed())
-
- 2010-12-22
Entfernen Sie die Standardfelder des Benutzerprofilsfür Kontaktinformationen undersetzen Sie sie durchetwas Benutzerfreundlicheres.
Der zweite Teil dieser Funktion wurdebereits obenerwähnt,aber das Entfernen der Standardfelder - AIM,Yahoo IM und Jabber/Google Talk -nochnicht:
function update_contact_methods( $contactmethods ) { // Remove annoying and unwanted default fields unset($contactmethods['aim']); unset($contactmethods['jabber']); unset($contactmethods['yim']); // Add new fields $contactmethods['phone'] = 'Phone'; $contactmethods['mobile'] = 'Mobile'; $contactmethods['address'] = 'Address'; return $contactmethods; } add_filter('user_contactmethods', 'update_contact_methods');
Natürlich können Sie unter "Neue Felder hinzufügen"
beliebig viele Felder hinzufügen (siehe vorherige Beispiele weiter obenin diesem Thread)Remove default fields contact info user profile and replace them with something more usable
The second part of this function has already been mentioned above, but removing the default fields - AIM, Yahoo IM and Jabber/Google Talk - not yet:
function update_contact_methods( $contactmethods ) { // Remove annoying and unwanted default fields unset($contactmethods['aim']); unset($contactmethods['jabber']); unset($contactmethods['yim']); // Add new fields $contactmethods['phone'] = 'Phone'; $contactmethods['mobile'] = 'Mobile'; $contactmethods['address'] = 'Address'; return $contactmethods; } add_filter('user_contactmethods', 'update_contact_methods');
Of course you can add as many fields as you want (see previous examples earlier in this thread) under "Add new fields"
-
- 2011-11-10
Vorbelegung von Beitragstypen
Hieristeine für diese Sammlung.
//////////////////////////////////////////////////////////////////////////////////// // This auto populates post types and posts. /////////////////////////////////////////////////////////////////////////////////// add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $content ) { global $post_type; switch( $post_type ) { case 'your_post_type_here': //auto populate $content = 'The content you want to pre-populate the post type with.'; break; } return $content; }
Dies kannnützlich sein,wenn Sie dieselben Informationenmit geringfügigen Unterschiedenimmer wieder veröffentlichenmüssen.
Pre-populating post types
Here is one for this collection.
//////////////////////////////////////////////////////////////////////////////////// // This auto populates post types and posts. /////////////////////////////////////////////////////////////////////////////////// add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $content ) { global $post_type; switch( $post_type ) { case 'your_post_type_here': //auto populate $content = 'The content you want to pre-populate the post type with.'; break; } return $content; }
This can come in handy for when you need to post the same info over and over again with slight differences.
-
Schön!Ichmag dieseeinfache Option.Können Sie dieserweitern,indem Sie Möglichkeiten zum automatischen Ausfüllenbenutzerdefinierter Felder oder anderer Kriterien/Optionen odermöglicherweise sogar die Mittel zum automatischen Einfügen von Medien anzeigen?Nice one! I like this simple option. Can you expand this by possible showing ways of automatically populating custom fields or other criteria/options or possibly even the means of auto-inserting media?
- 0
- 2011-11-11
- NetConstructor.com
-
Ich kann definitiv sehen,wiemaneserweitert.Ich habenochnicht wirklich versucht,es weiter zubringen.I can definitely see about expanding it. I have not really tried taking it further yet.
- 0
- 2011-11-14
- Nicole
-
Würdegerne Möglichkeiten sehen,dies zuerweiternWould love to see ways to expand this
- 0
- 2012-04-11
- JasonDavis
-
- 2010-09-15
Google Analytics-Code automatischeinschließen
Getestet am: Wordpress 3.1 RC3
Ich verwende dieses Skript seit WordPress 2.3.0 auf allenmeinen Websites. Esfügt lediglich die Standard-Google-Tracking-Skripte zur Fußzeile hinzu.
// Add Google Analytics Tracking Code function add_google_analytics() { ?> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-XXXXXXX-X"); pageTracker._trackPageview(); } catch(err) {}</script> <?php } add_action('wp_footer', 'add_google_analytics');
Ersetzen Sie
UA-XXXXXXX-X
unbedingt durch Ihreneigenen Google-Tracking-Code ...Auto Include Google Analytics Code
Tested on: Wordpress 3.1 RC3
I've been using this script on all of my sites since WordPress 2.3.0 ... it just adds the standard Google tracking scripts to the footer.
// Add Google Analytics Tracking Code function add_google_analytics() { ?> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-XXXXXXX-X"); pageTracker._trackPageview(); } catch(err) {}</script> <?php } add_action('wp_footer', 'add_google_analytics');
Just be sure to replace
UA-XXXXXXX-X
with your own Google tracking code...-
dankefür denteil.Ich habe auch dieses verwendet,aberich wäregespannt,ob Sie wissen,wie diesgeändert werden kann,damitbestimmten Tags,Postseitenseiten oder sogar Posts selbst zusätzliche Werte übergeben werden können,wobei die Var-Funktionenfür die Kampagnenverfolgung automatisch verwendet werdenGooglebietet.Wasmüsste außerdem hinzugefügt werden,wenn wir diesin die Fußzeile aller Administrationsseiteneinfügenmöchten,um die Administratoraktivität zu verfolgen?thanks for the share. I have been using this one as well but I would be curious to know if you are aware how this can be modified so that specific tags, post type pages or even posts themself can be passed additional values automatically making use of the campaign tracking var capabilities google provides. Additionally, what would need to be added if we wanted to add this to the footer of all admin pages to track admin activity?
- 0
- 2010-09-17
- NetConstructor.com
-
Ichbin mirnicht sicher,obich Kampagnen-Tracking-Variablen hinzufügen soll,nur weilich dasnochnichtgebraucht habe.Um den Administrationsseiten dieselben Skripte hinzuzufügen,verwenden Sieeinfach "add_action" ("admin_footer","add_google_analytics"),um sichin die Fußzeile der Administrationsseiteneinzubinden.Not sure about adding campaign tracking variables only because I haven't had a need for that yet. But to add the same scripts to admin pages, you'd just use `add_action('admin_footer', 'add_google_analytics');` to hook on to the footer of admin pages.
- 1
- 2010-09-17
- EAMann
-
- 2010-09-17
Listet alle Konstanten zur Information und zum Debuggen auf
Getestet am: Wordpress 3.0.1
Zeigt die Informationennur an,wenn Sieein angemeldeter Benutzer sind
if ( is_user_logged_in() ) { print('<pre>'); print_r( @get_defined_constants() ); print('</pre>'); }
Hieristeine Versionmit optionalem Filter,dieteilweisemit konstanten Namen und Werten übereinstimmt:
function constants($filter = false) { $constants = get_defined_constants(); if( $filter ) { $temp = array(); foreach ( $constants as $key => $constant ) if( false !== stripos( $key, $filter ) || false !== stripos( $constant, $filter ) ) $temp[$key] = $constant; $constants = $temp; } ksort( $constants ); var_dump( $constants ); }
List all constants for information and debugging
Tested on: Wordpress 3.0.1
Will only display the information if you are a logged in user
if ( is_user_logged_in() ) { print('<pre>'); print_r( @get_defined_constants() ); print('</pre>'); }
Here is version with optional filter that will partially match constant names and values:
function constants($filter = false) { $constants = get_defined_constants(); if( $filter ) { $temp = array(); foreach ( $constants as $key => $constant ) if( false !== stripos( $key, $filter ) || false !== stripos( $constant, $filter ) ) $temp[$key] = $constant; $constants = $temp; } ksort( $constants ); var_dump( $constants ); }
-
-
Dies aktualisiert also automatisch alle Plugins,wennetwas Neues verfügbarist.so this automatically updates any/all of your plugins whenever something new is available?
- 0
- 2010-11-05
- NetConstructor.com
-
Nein,Siebrauchennur kein FTP-Login,um Ihren Core oder Ihre Plugins lokal zu aktualisierenNope, you just don't need a ftp login to update your core or plugins locally
- 0
- 2010-11-09
- Horttcore
-
-
- 2010-12-21
Standardautor Slug ändern
Fügen Sie diesin Ihre Funktionenein,um den Standard-Author-Slugnach Ihren Wünschen zu ändern.
Ändern Sieeinfach die "Verkäufer"in diegewünschte Schnecke.// Change URL Slug from Author to Sellers function new_author_base() { global $wp_rewrite; $author_slug = 'sellers'; $wp_rewrite->author_base = $author_slug; } add_action('init', 'new_author_base');
Change default Author Slug
Put this in your functions to change the default Author Slug to whatever you want,
just change the "sellers" to the slug you want.// Change URL Slug from Author to Sellers function new_author_base() { global $wp_rewrite; $author_slug = 'sellers'; $wp_rewrite->author_base = $author_slug; } add_action('init', 'new_author_base');
-
Siemöchten diesen Codejedochnichtbei jedem Laden der Seite ausführen.You'd not want to run that code on every page load however.
- 4
- 2010-12-21
- t31os
-
Ja,das Löschen von Rollenbei jeder Ladungerspart Ihnen viele Verkäufer.:) Verwenden Siebesser das Plugin [Edit Author Slug] (http://brandonallen.org/wordpress/plugins/edit-author-slug/).Yeah, flushing roles on every load saves you a lot of sellers. :) Better use the plugin [Edit Author Slug](http://brandonallen.org/wordpress/plugins/edit-author-slug/).
- 0
- 2010-12-22
- fuxia
-
Ich habe die Funktion aktualisiert !!!Dankefür deinen Beitrag:)I have update the function!!! Thanks for your input:)
- 0
- 2011-01-12
- Philip
-
- 2011-01-02
Fügen Sie die Schaltfläche "Nächste Seite"im WYSIYG-Editor
hinzuadd_filter('mce_buttons','wysiwyg_editor'); function wysiwyg_editor($mce_buttons) { $pos = array_search('wp_more',$mce_buttons,true); if ($pos !== false) { $tmp_buttons = array_slice($mce_buttons, 0, $pos+1); $tmp_buttons[] = 'wp_page'; $mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1)); } return $mce_buttons; }
Add "Next-page"-button in WYSIYG-editor
add_filter('mce_buttons','wysiwyg_editor'); function wysiwyg_editor($mce_buttons) { $pos = array_search('wp_more',$mce_buttons,true); if ($pos !== false) { $tmp_buttons = array_slice($mce_buttons, 0, $pos+1); $tmp_buttons[] = 'wp_page'; $mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1)); } return $mce_buttons; }
-
- 2011-01-04
Fügen Sie dem TinyMCE-Editorbenutzerdefinierte Stile hinzu
Manchmal sind Benutzer und Kunden verwirrt darüber,wieihre Inhalteim Editor angezeigt werden und wie sieim Front-End angezeigt werden.Das Kopierennureiniger relevanter Zeilen aus Ihrem Haupt-Stylesheetin Ihreneuetinymce.css kann sehr hilfreich sein:
function custom_mce_css($wp) { return $wp .= ',' . get_bloginfo('stylesheet_directory') . '/css/tinymce.css'; } add_filter( 'mce_css', 'custom_mce_css' );
Add custom styles to TinyMCE editor
Sometimes users and clients get confused about how their content is displayed in the editor versus how it is displayed on the front-end. Copying just a few relevant lines from your main stylesheet into your new tinymce.css can help a lot:
function custom_mce_css($wp) { return $wp .= ',' . get_bloginfo('stylesheet_directory') . '/css/tinymce.css'; } add_filter( 'mce_css', 'custom_mce_css' );
-
Nett.Ich habegerade herausgefunden,dasseseine Lösung von Seamus Leahygibt,die all dieseinen Schritt weitererweitert,indem sie Tinymceeine Körperklasse hinzufügt.http://www.digwp.com/2010/11/actual-wysiwygNice. Ive just discoverd there is a solution by Seamus Leahy that extends all this one step further by adding a body class to tinymce. http://www.digwp.com/2010/11/actual-wysiwyg
- 0
- 2011-01-20
- Michal Mau
-
Wird diesnichtbereits durch Kern- und Editorstile abgedeckt?Isn't this already covered by core & editor styles?
- 0
- 2011-02-01
- kaiser
-
Ichbevorzugees,ein Stylesheetfür Front-End und TinyMCE aufeinmal zuerstellen.Dann verwendeich die Kernfunktionalität der Funktion add_editor_style (),um das Stylesheeteinzuschließen und sicherzustellen,dassesbeim Laden von TinyMCEgeladen wird.Codex-Artikel unter http://codex.wordpress.org/Function_Reference/add_editor_styleI prefer to create a stylesheet for both front-end and TinyMCE in one go. Then I use core functionality of the add_editor_style() function to include the stylesheet and ensure it's loaded when TinyMCE loads. Codex article at http://codex.wordpress.org/Function_Reference/add_editor_style
- 0
- 2011-09-13
- Philip Downer
-
- 2011-06-08
Verwenden Siefigur undfigcaptionfürbeschriftungen
Getestet auf: WordPress 3.1.3
(Dank an WP Engineer: http://wpengineer.com/917/filter-caption- Shortcode-in-WordPress/)
function mytheme_caption( $attr, $content = null ) { $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); if ( $output != '' ) return $output; extract( shortcode_atts ( array( 'id' => '', 'align' => 'alignnone', 'width'=> '', 'caption' => '' ), $attr ) ); if ( 1 > (int) $width || empty( $caption ) ) return $content; if ( $id ) $id = 'id="' . $id . '" '; return '<figure ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . $width . 'px">' . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $caption . '</figcaption></figure>'; } add_shortcode( 'wp_caption', 'mytheme_caption' ); add_shortcode( 'caption', 'mytheme_caption' );
Use figure and figcaption for captions
Tested on: WordPress 3.1.3
(Credits to WP Engineer: http://wpengineer.com/917/filter-caption-shortcode-in-wordpress/)
function mytheme_caption( $attr, $content = null ) { $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); if ( $output != '' ) return $output; extract( shortcode_atts ( array( 'id' => '', 'align' => 'alignnone', 'width'=> '', 'caption' => '' ), $attr ) ); if ( 1 > (int) $width || empty( $caption ) ) return $content; if ( $id ) $id = 'id="' . $id . '" '; return '<figure ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . $width . 'px">' . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $caption . '</figcaption></figure>'; } add_shortcode( 'wp_caption', 'mytheme_caption' ); add_shortcode( 'caption', 'mytheme_caption' );
-
- 2012-01-08
Hier sindeinige nette Shortcodes,die Sie verwenden können:
1. Einfach hinzuzufügender Shortcodefür Twitter- und Facebook-Freigabeknöpfe
function shreplz() { return ' <div class="sharebox"> <div class="twittme"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"></script></div> <div class="shareface"><a name="fb_share"></a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></div> <br style="clear: left;" /> </div> '; } add_shortcode('sharethis', 'shreplz'); // How to use: [sharethis]
2. Einfacher Remote-Site-Snapshotmit dem WordPress-API-Shortcode
function wpr_snap($atts, $content = null) { extract(shortcode_atts(array( "snap" => 'http://s.wordpress.com/mshots/v1/', "url" => 'http://www.sagive.co.il', "alt" => 'My image', "w" => '400', // width "h" => '300' // height ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode("snap", "wpr_snap"); // How to use: [snap url="http://www.example.com" alt="Cool Site!" w="300px" h="200px"]
3. Einfach zubedienen & amp; Einbetten desiFrame-Shortcodes
function GenerateIframe( $atts ) { extract( shortcode_atts( array( 'href' => 'http://the-url', 'height' => '550px', 'width' => '600px', ), $atts ) ); return '<iframe src="'.$href.'" width="'.$width.'" height="'.$height.'"> <p>Your Browser does not support Iframes.</p></iframe>'; } add_shortcode('iframe', 'GenerateIframe'); // How to use: [iframe href="http://www.exmaple.com" height="480" width="640"]
4. Einfacheinzuschließende Remote-Datei/Dokumentmit Shortcode
function getfile_content( $atts ) { extract( shortcode_atts( array( 'fileurl' => '' ), $atts ) ); if ($fileurl!='') return @file_get_contents($fileurl); } add_shortcode( 'getfile', 'getfile_content' ); // How to use: [getfile fileurl="http://www.exmaple.com/somepage.html"]
. Hier sindeinige kommentarbezogene Ausschnitte:
1. Schließen Sie die Möglichkeit zumglobalen Kommentieren
function closeCommentsGlobaly($data) { return false; } add_filter('comments_number', 'closeCommentsGlobaly'); add_filter('comments_open', 'closeCommentsGlobaly');
2. Geben Sie dem Administratoreine andere CSS-Klassefür die Kommentare des Administrators
if (1 == $comment->user_id) echo 'siteadmin'; // Pick your class here
3. Ein wirklich cooler Richmit einer Datenliste von Kommentaren -gr8fürbenutzerdefiniertegesperrte Seite
$comments = get_comments( array( 'number' => 10, // How many comments 'status' => 'approve' // Type of comments ) ); foreach($comments as $eachComment){ // Collect the data and assign it $commentID = comment_ID; $commentAuthorEmail = $eachComment->comment_author_email; $commentPostId = $eachComment->comment_post_ID; $commentPostTitle = get_the_title( $commentPostId ); $commentPostUrl = get_permalink( $commentPostId ); $comment_sidebarnumber = get_comments_number( $commentPostId ); global $wpdb; $userCommentCount = $wpdb->get_var('SELECT COUNT('.$commentID.') FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . $commentAuthorEmail . '"'); echo '<div style="border: 1px solid #ccc; padding: 10px;">'; echo '<ul style="margin: 0px;">'; echo '<li>Name: '. $eachComment->comment_author .'</li>'; echo '<li>Commented about: <a href="'.$commentPostUrl.'">'. $commentPostTitle .'</a></li>'; echo '<li>Commented On: '. $eachComment->comment_date .'</li>'; echo '<li>Commneter Site: '. $eachComment->comment_author_email .'</</li>'; echo '<li>Commenter Email: '. $eachComment->comment_author_email .'</</li>'; echo '<li>This Commenter'. $eachComment->comment_author .' Commented '. $userCommentCount .' on your site</</li>'; echo '</ul>'; echo '<p style="padding: 10px;"><strong>'. $eachComment->comment_author .' wrote</strong>: '. $eachComment->comment_content .'</p>'; echo '</div>'; }
Here are some nice shortcodes for you to use:
1. Easy-to-add Twitter and Facebook share button shortcode
function shreplz() { return ' <div class="sharebox"> <div class="twittme"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"></script></div> <div class="shareface"><a name="fb_share"></a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></div> <br style="clear: left;" /> </div> '; } add_shortcode('sharethis', 'shreplz'); // How to use: [sharethis]
2. Easy remote site snapshot using WordPress API shortcode
function wpr_snap($atts, $content = null) { extract(shortcode_atts(array( "snap" => 'http://s.wordpress.com/mshots/v1/', "url" => 'http://www.sagive.co.il', "alt" => 'My image', "w" => '400', // width "h" => '300' // height ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode("snap", "wpr_snap"); // How to use: [snap url="http://www.example.com" alt="Cool Site!" w="300px" h="200px"]
3. Easy to use & embed iFrame shortcode
function GenerateIframe( $atts ) { extract( shortcode_atts( array( 'href' => 'http://the-url', 'height' => '550px', 'width' => '600px', ), $atts ) ); return '<iframe src="'.$href.'" width="'.$width.'" height="'.$height.'"> <p>Your Browser does not support Iframes.</p></iframe>'; } add_shortcode('iframe', 'GenerateIframe'); // How to use: [iframe href="http://www.exmaple.com" height="480" width="640"]
4. Easy-to-include remote file / doc with shortcode
function getfile_content( $atts ) { extract( shortcode_atts( array( 'fileurl' => '' ), $atts ) ); if ($fileurl!='') return @file_get_contents($fileurl); } add_shortcode( 'getfile', 'getfile_content' ); // How to use: [getfile fileurl="http://www.exmaple.com/somepage.html"]
. Here are some comments related snippets:
1. Close the ability to comment globally
function closeCommentsGlobaly($data) { return false; } add_filter('comments_number', 'closeCommentsGlobaly'); add_filter('comments_open', 'closeCommentsGlobaly');
2. Give the administrator a different CSS class for the administrator's comments
if (1 == $comment->user_id) echo 'siteadmin'; // Pick your class here
3. A really cool rich with a data list of comments - gr8 for custom locked page
$comments = get_comments( array( 'number' => 10, // How many comments 'status' => 'approve' // Type of comments ) ); foreach($comments as $eachComment){ // Collect the data and assign it $commentID = comment_ID; $commentAuthorEmail = $eachComment->comment_author_email; $commentPostId = $eachComment->comment_post_ID; $commentPostTitle = get_the_title( $commentPostId ); $commentPostUrl = get_permalink( $commentPostId ); $comment_sidebarnumber = get_comments_number( $commentPostId ); global $wpdb; $userCommentCount = $wpdb->get_var('SELECT COUNT('.$commentID.') FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . $commentAuthorEmail . '"'); echo '<div style="border: 1px solid #ccc; padding: 10px;">'; echo '<ul style="margin: 0px;">'; echo '<li>Name: '. $eachComment->comment_author .'</li>'; echo '<li>Commented about: <a href="'.$commentPostUrl.'">'. $commentPostTitle .'</a></li>'; echo '<li>Commented On: '. $eachComment->comment_date .'</li>'; echo '<li>Commneter Site: '. $eachComment->comment_author_email .'</</li>'; echo '<li>Commenter Email: '. $eachComment->comment_author_email .'</</li>'; echo '<li>This Commenter'. $eachComment->comment_author .' Commented '. $userCommentCount .' on your site</</li>'; echo '</ul>'; echo '<p style="padding: 10px;"><strong>'. $eachComment->comment_author .' wrote</strong>: '. $eachComment->comment_content .'</p>'; echo '</div>'; }
-
- 2010-12-18
Erstellen Sieein bedingtes Tagfürbenutzerdefinierte Taxonomien
In diesem Beispiel war 'student'ein benutzerdefinierter Beitragstyp und 'stud_cat' diebenutzerdefinierte Taxonomie.Verwenden Sie
has_student(null)
für die Bedingungfunction has_student( $student, $_post = null ) { if ( !empty( $student ) ) return false; if ( $_post ) $_post = get_post( $_post ); else $_post =& $GLOBALS['post']; if ( !$_post ) return false; $r = is_object_in_term( $_post->ID, 'studcat', $student ); if ( is_wp_error( $r ) ) return false; return $r; }
Create a conditional tag for custom taxonomies
In this example, 'student' was a custom post type, and 'stud_cat' was the custom taxonomy. Use
has_student(null)
for the conditionalfunction has_student( $student, $_post = null ) { if ( !empty( $student ) ) return false; if ( $_post ) $_post = get_post( $_post ); else $_post =& $GLOBALS['post']; if ( !$_post ) return false; $r = is_object_in_term( $_post->ID, 'studcat', $student ); if ( is_wp_error( $r ) ) return false; return $r; }
-
Ich denke,dies wird durch [`has_term ()`] (http://codex.wordpress.org/Function_Reference/has_term)ersetzt,nachdem 3.1 veröffentlicht wurde?I think this gets replaced with [`has_term()`](http://codex.wordpress.org/Function_Reference/has_term) now that 3.1 is released?
- 1
- 2011-02-25
- Rarst
-
- 2010-12-28
WordPress-EditoriFrames zulassen
//TinyMCE dazubringen,Iframes zuzulassen add_filter ('tiny_mce_before_init',create_function ('$ a', '$ a ["extended_valid_elements"]="iframe [id| class| title| style| align| frameborder| height| longdesc| marginheight| marginwidth| name| scrolling| src| width]";return $ a; '));
Make WordPress Editor Allow iFrames
// make TinyMCE allow iframes add_filter('tiny_mce_before_init', create_function( '$a', '$a["extended_valid_elements"] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]"; return $a;') );
-
- 2011-02-10
Ändern Sie die Größeeinesgroßen Bildesbeim Hochladen
Die Bildgröße wirdentsprechend der Größein Ihren Medieneinstellungengeändert.
/**resize on upload to the largest size in media setting */ function replace_uploaded_image($image_data) { // if there is no large image : return if (!isset($image_data['sizes']['large'])) return $image_data; // path to the uploaded image and the large image $upload_dir = wp_upload_dir(); $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // delete the uploaded image unlink($uploaded_image_location); // rename the large image rename($large_image_location,$uploaded_image_location); // update image metadata and return them $image_data['width'] = $image_data['sizes']['large']['width']; $image_data['height'] = $image_data['sizes']['large']['height']; unset($image_data['sizes']['large']); return $image_data; } add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
Resize large image on upload
Image will be resize according to the large size in your media settings.
/**resize on upload to the largest size in media setting */ function replace_uploaded_image($image_data) { // if there is no large image : return if (!isset($image_data['sizes']['large'])) return $image_data; // path to the uploaded image and the large image $upload_dir = wp_upload_dir(); $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // delete the uploaded image unlink($uploaded_image_location); // rename the large image rename($large_image_location,$uploaded_image_location); // update image metadata and return them $image_data['width'] = $image_data['sizes']['large']['width']; $image_data['height'] = $image_data['sizes']['large']['height']; unset($image_data['sizes']['large']); return $image_data; } add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
-
Bedeutet dies,dass die ursprünglich hochgeladenegroße Dateitatsächlichersetzt wird?Mein PHPistnichtgroßartig,aber die Antwort scheintja zu sein?Does this mean that the original large file uploaded is actually replaced? My php is not great, but the answer seems to be yes?
- 0
- 2011-02-20
- davemac
-
@davemac Mirist klar,dass diesjetzt sehr altist,abernachmeinem Verständnis des Codes wird die Größe der Originalbilddatei auf diegleichen Abmessungen wie dieim WordPress-Einstellungsbildschirmfestgelegte 'große' Bildgrößegeändert.Dasistgroßartig,aber dann haben Sienur 2 Bilder dergleichen Größe.Ich würde vorschlagen,die Wertemanuellfestzulegen,damit das Originalbildnur sogroßist wie diegrößte Datei,die Siejemals realistisch auf Ihrer Site verwenden werden.Dann haben Sieein fast originelles Bild,mit dem Siein Zukunft arbeiten können.@davemac I realise this is very old now, but from what I understand of the code, the original image file is resized to the same dimensions as the 'large' image size set in the WordPress settings screen. Which is great but then you just end up with 2 images of the same size. I'd suggest manually setting the values to make the original image only as big as the largest file you will ever realistically use on your site. Then you have an almost original image to work with in future.
- 0
- 2016-11-25
- Phill Healey
-
- 2011-09-14
Einfache WordPress-Sicherheitskorrekturen
Sicherheit durch Dunkelheitist hier der Name des Spiels. Diese Funktionenmachen drei verschiedene Dinge.
- Entfernen Sie die Versionszeichenfolge aus dem Code. Esmacht keinen Sinn,den Leuten zu sagen,welche Version wir verwenden.
- Entfernt alle Fehlermeldungen (falsches Passwort,kein solcher Benutzer usw.) aus den Administrator-Anmeldebildschirmen
-
Wenn der Administratoreinen Kommentar veröffentlicht,wirdeine CSS-Klasse hinzugefügt. Dadurch wird der Administratornamein den Kommentarenentfernt.
//REMOVE VERSION STRING FROM HEADER remove_action('wp_head', 'wp_generator'); //HIDE LOGIN ERROR MESSAGES (Wrong Password, No Such User etc.) add_filter('login_errors',create_function('$a', "return null;")); // Remove admin name in comments class // Source: http://www.wprecipes.com/wordpress-hack-remove-admin-name-in-comments-class function remove_comment_author_class( $classes ) { foreach( $classes as $key => $class ) { if(strstr($class, "comment-author-")) { unset( $classes[$key] ); } } return $classes; } add_filter( 'comment_class' , 'remove_comment_author_class' );
Easy WordPress Security Fixes
Security through obscurity is the name of the game here. These functions do three different things.
- Remove the version string from the code. No point in telling folks what version we're running.
- Removes any error messages (Wrong Password, No Such User, etc.) from admin login screens
When the admin posts a comment, a CSS class is added. This removes the admin name in comments.
//REMOVE VERSION STRING FROM HEADER remove_action('wp_head', 'wp_generator'); //HIDE LOGIN ERROR MESSAGES (Wrong Password, No Such User etc.) add_filter('login_errors',create_function('$a', "return null;")); // Remove admin name in comments class // Source: http://www.wprecipes.com/wordpress-hack-remove-admin-name-in-comments-class function remove_comment_author_class( $classes ) { foreach( $classes as $key => $class ) { if(strstr($class, "comment-author-")) { unset( $classes[$key] ); } } return $classes; } add_filter( 'comment_class' , 'remove_comment_author_class' );
-
Das Entfernen der Wordpress-Versionsnummeristeine schlechte Praxis.Esist viel sicherer,Ihr Wordpressjederzeitmit denneuesten Sicherheitskorrekturen auf demneuesten Stand zu halten.Zusätzlicher Bonus: Möchtegern-Skriptkinder werden zu älteren Versionen wechseln.Removing the Wordpress version number is bad practice. It is much safer to keep your Wordpress updated with the latest security fixes AT ALL TIMES. Added bonus: wanna-be script kiddies will move along to older versions.
- 0
- 2014-01-12
- knutole
-
@knotole,esist keine schlechte Praxis.Esist Ihre Meinung ... obwohl dies ziemlichnormalist.@knotole, it is not bad practice. It is your opinion... albeit this is pretty standard.
- 2
- 2014-10-20
- Jeremy
-
- 2011-09-14
Standard-Gravatar durchbenutzerdefiniertes Bildersetzen
Siemüssen lediglich den Pfad zu Ihrem Standardbild anpassen.
function custom_gravatar($avatar_defaults) { $logo = get_bloginfo('template_directory') . '/images/icons/gravatar_logo.jpg'; //Change to whatever path you like. $avatar_defaults[$logo] = get_bloginfo('name'); return $avatar_defaults; }//END FUNCTION add_filter( 'avatar_defaults', 'custom_gravatar' );
Replace Default Gravatar with Custom Image
All you'll need to customize is the path to your default image.
function custom_gravatar($avatar_defaults) { $logo = get_bloginfo('template_directory') . '/images/icons/gravatar_logo.jpg'; //Change to whatever path you like. $avatar_defaults[$logo] = get_bloginfo('name'); return $avatar_defaults; }//END FUNCTION add_filter( 'avatar_defaults', 'custom_gravatar' );
-
- 2011-10-13
Zeigt dieenthaltenen Vorlagendateien an
Zeigt Inline-Kommentaremit Vorlagendateien undget_template_part-Dateien an,diebeim Rendern von Seitenenthalten sind.Praktisch zur Fehlerbehebungbei mehrteiligen Vorlagen.
add_action('all','template_snoop'); function template_snoop(){ $args = func_get_args(); if( !is_admin() and $args[0] ){ if( $args[0] == 'template_include' ) { echo "<!-- Base Template: {$args[1]} -->\n"; } elseif( strpos($args[0],'get_template_part_') === 0 ) { global $last_template_snoop; if( $last_template_snoop ) echo "\n\n<!-- End Template Part: {$last_template_snoop} -->"; $tpl = rtrim(join('-', array_slice($args,1)),'-').'.php'; echo "\n<!-- Template Part: {$tpl} -->\n\n"; $last_template_snoop = $tpl; } } }
Show template files being included
Display inline comment with Template File and get_template_part files being included when rendering pages. Handy for troubleshooting multipart templates.
add_action('all','template_snoop'); function template_snoop(){ $args = func_get_args(); if( !is_admin() and $args[0] ){ if( $args[0] == 'template_include' ) { echo "<!-- Base Template: {$args[1]} -->\n"; } elseif( strpos($args[0],'get_template_part_') === 0 ) { global $last_template_snoop; if( $last_template_snoop ) echo "\n\n<!-- End Template Part: {$last_template_snoop} -->"; $tpl = rtrim(join('-', array_slice($args,1)),'-').'.php'; echo "\n<!-- Template Part: {$tpl} -->\n\n"; $last_template_snoop = $tpl; } } }
-
- 2011-12-04
Erstellen Sie automatischeine neue Seite,wenn Sieein Thema aktivieren.
if (isset($_GET['activated']) && is_admin()){ $new_page_title = 'This is the page title'; $new_page_content = 'This is the page content'; $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template. //don't edit under this line $page_check = get_page_by_title($new_page_title); $new_page = array( 'post_type' => 'page', 'post_title' => $new_page_title, 'post_content' => $new_page_content, 'post_status' => 'publish', 'post_author' => 1, ); if(!isset($page_check->ID)){ $new_page_id = wp_insert_post($new_page); if(!empty($new_page_template)){ update_post_meta($new_page_id,'_wp_page_template', $new_page_template); } }
Automatically create a new page upon activating a theme
if (isset($_GET['activated']) && is_admin()){ $new_page_title = 'This is the page title'; $new_page_content = 'This is the page content'; $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template. //don't edit under this line $page_check = get_page_by_title($new_page_title); $new_page = array( 'post_type' => 'page', 'post_title' => $new_page_title, 'post_content' => $new_page_content, 'post_status' => 'publish', 'post_author' => 1, ); if(!isset($page_check->ID)){ $new_page_id = wp_insert_post($new_page); if(!empty($new_page_template)){ update_post_meta($new_page_id,'_wp_page_template', $new_page_template); } }
-
- 2010-09-17
Alle Unterkategorien auflisten
Getestet am: Wordpress 3.0.1
$echo = '<ul>' . "\n"; $childcats = get_categories('child_of=' . $cat . '&hide_empty=1'); foreach ($childcats as $childcat) { if (1 == $childcat->category_parent) { $echo .= "\t" . '<li><a href="' . get_category_link($childcat->cat_ID).'" title="' . $childcat->category_description . '">'; $echo .= $childcat->cat_name . '</a>'; $echo .= '</li>' . "\n"; } } $echo .= '</ul>' . "\n"; echo $echo;
auch hier weitere Informationen und Funktionenin der Post http://wpengineer.com/2025/Liste aller Unterkategorien/
List all SubCategories
Tested on: Wordpress 3.0.1
$echo = '<ul>' . "\n"; $childcats = get_categories('child_of=' . $cat . '&hide_empty=1'); foreach ($childcats as $childcat) { if (1 == $childcat->category_parent) { $echo .= "\t" . '<li><a href="' . get_category_link($childcat->cat_ID).'" title="' . $childcat->category_description . '">'; $echo .= $childcat->cat_name . '</a>'; $echo .= '</li>' . "\n"; } } $echo .= '</ul>' . "\n"; echo $echo;
also here, more informations and functins in the post http://wpengineer.com/2025/list-all-subcategories/
-
Warum sollten Sie diestun,wenneine Funktion speziell zum Anzeigeneiner Liste von Kategorien verfügbarist? Siehe: http://codex.wordpress.org/Template_Tags/wp_list_categories#Only_Show_Children_of_a_CategoryWhy would you do this when there's a function available specifically for displaying a list of categories..See: http://codex.wordpress.org/Template_Tags/wp_list_categories#Only_Show_Children_of_a_Category
- 1
- 2010-11-11
- t31os
-
- 2010-11-09
Schließen Sie untergeordnete Kategorieneinerbestimmten Kategorie aus.
Ziemlicheinfach,aberich konnteniemandenfinden,dergenau dastat,wasichbrauchte.Außerdem wird der Beitrag angezeigt,wenn die übergeordnete Kategorie ausgewähltist,außer wennfür diesen Beitrageine untergeordnete Kategorie dieses übergeordneten Elements ausgewähltist.
/* this code excludes all of the children of (category id = 20) posts on the HOME page, but allows parent (category id = 20) to be shown. */ function exclude_category_children($query) { $child_cats = (array) get_term_children('20', 'category'); if ( $query->is_home ) { $query->set('category__not_in', $child_cats); return $query; } } add_filter('pre_get_posts', 'exclude_category_children');
Exclude child categories of a specific category.
Pretty straight forward, but I couldn't find anyone doing exactly what I needed. Also it will display the post if the parent category is selected, except if that post has a child category of that parent selected.
/* this code excludes all of the children of (category id = 20) posts on the HOME page, but allows parent (category id = 20) to be shown. */ function exclude_category_children($query) { $child_cats = (array) get_term_children('20', 'category'); if ( $query->is_home ) { $query->set('category__not_in', $child_cats); return $query; } } add_filter('pre_get_posts', 'exclude_category_children');
-
- 2010-12-02
Voraussetzungfür die Überprüfung auf Hierarchie-Nachkommen
Einebedingte Funktion,mit der überprüft wird,ob die aktuelle Seiteein Nachkomme derihr zugewiesenen IDist.Nützlich,umfestzustellen,obeine Seiteein Enkel,ein Urenkel oderein Vaterim Hierarchiebaumist.
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page $anc = get_post_ancestors( $post->ID ); foreach($anc as $ancestor) { if(is_page() && $ancestor == $pid) { return true; } } if(is_page()&&(is_page($pid))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };
Conditional to check for hierarchy descendant
A conditional function to check if the current page is a descendant of the ID given to it. Useful for determining if a page is a grandchild, great-grandchild or father down the hierarchy tree.
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page $anc = get_post_ancestors( $post->ID ); foreach($anc as $ancestor) { if(is_page() && $ancestor == $pid) { return true; } } if(is_page()&&(is_page($pid))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };
-
Ich habeeine Weile danachgesucht.Danke,dass dues zusammengestellt hast!Kannich umeine Klarstellung des Anwendungsfallsbitten?Im Idealfallmöchteich diesin meinen Menüeinträgen verwenden,damitich oben auf der Siteein übergeordnetes Menü der obersten Ebene habe,in demnur Elemente der 1. Generation angezeigt werden.Wennichmichin einem Gen 2-3-Elementbefinde,kann das Gen1-Element überein CSS-Attribut "current-parent" hervorgehoben werden.Ist dasmöglich?I've been looking for this for awhile. Thanks for putting it together! Can I ask for a bit of clarification on use case. Ideally, I would like to use this in my menu listings so that if i have a top level parent menu across the top of the site that only shows Gen 1 elements. When I'm on a Gen 2-3 element, the Gen1 element can be highlighted via a "current-parent" css attribute. Is this possible?
- 0
- 2011-02-11
- Scott B
-
- 2011-06-13
Entfernen Sie die Admin-Backend-Menüsfür alle Benutzermit Ausnahme von Benutzer Nr. 1 (normalerweise dererste Administrator)
/*-----------------------------------------------------------------------------------*/ /* Restrict access /*-----------------------------------------------------------------------------------*/ function remove_menus () { global $menu; $user = wp_get_current_user(); if ($user->ID!=1) { // Is not administrator, $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} } } } add_action('admin_menu', 'remove_menus');
Remove Admin Backend Menus for all users, except User #1 (usually the first Admin)
/*-----------------------------------------------------------------------------------*/ /* Restrict access /*-----------------------------------------------------------------------------------*/ function remove_menus () { global $menu; $user = wp_get_current_user(); if ($user->ID!=1) { // Is not administrator, $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} } } } add_action('admin_menu', 'remove_menus');
-
Benutzer 1 kann dererste Administrator sein.Nach dem Hinzufügenneuer Administratorenist dererstemöglicherweisenurein normaler Benutzer.** Fragen Sienach Funktionen,nichtnach Zahlen. ** Außerdemgehört dieser Codein ein Plugin,nichtin die Dateifunctions.php.Esgibt keine Beziehung zum Thema.User 1 may be the first admin. But after adding new administrators the first one may be just a regular user. **Ask for capabilities, not for numbers.** Plus, this code belongs into a plugin, not in the functions.php. There is zero relation to the theme.
- 0
- 2011-06-13
- fuxia
-
Auf diese Weise können Sie allen Administratorenerlauben,wiegewohnt zu handeln,abergleichzeitig denersten Administrator ausblenden undihn dem Systemadministrator/Support-Team reservieren.Ichbin nicht der Meinung,dass dieser Code zueinem Plugingehört.Functions.phpistein Plugin.`Diese Datei verhält sichim Grundegenommen wieein Plugin` [Theme_Development # Functions_File] (http://codex.wordpress.org/Theme_Development#Functions_File)This way you can allow all admins to act as normal but at the same time hide the first admin and reserve it to system administrator / support team. I disagree that this code belongs to a plugin. Functions.php is a plugin. `This file basically acts like a plugin` [Theme_Development#Functions_File](http://codex.wordpress.org/Theme_Development#Functions_File)
- 0
- 2011-06-13
- Daniel Sachs
-
Aber diefunctions.phpenthält Logik,die an das Themagebundenist,denn wenn Sie das Thema wechseln,ist dergesamte Code weg.Verwenden Sie die Dateifunctions.php alsonicht als Mu-Plugin,es sei denn,der Code hängt vom Thema ab und umgekehrt.But the functions.php contains logic which is tied to the theme, because if you switch themes the whole code is gone. So, unless the code depends on the theme and vice versa – do not use the functions.php as a mu-plugin.
- 0
- 2011-06-13
- fuxia
-
Ja.Aber lassen Sie uns Folgendesbedenken: Sieentwickelneine Websitefüreinen Kunden.Diese Website verwendetimmernurein Thema,das vom Designerentworfen wurde.Das Thema **ist ** die Website.Siefügenbenutzerdefinierte Beitragstypen,Metaboxen hinzu,laden zusätzliche Funktionen usw. Jetztmöchten Sieeinigen Benutzern die Verwaltungsfunktionengeben,aber Siemöchteneinige Abschnitte der Site ausblenden,die Ihr Clientniemals verwenden oder verwirren wird (Links,Tools,Kommentare sind diebesten Beispiele) undgeben dem Support-Teameine Art "SuperAdmin",damit sie dengesamten Administrationsbereich sehen können.Yes. But let's consider this: You are developing a website for a client. This website will always use only one theme, the one designed by the designer. The theme **is** the website. You add custom post types, metaboxes, load additional functions, etc. Now you do want to give some users the admin capabilities, but you want to hide some sections of the site that your client will never use or confuse them (Links, Tools, Comments, are the best examples) and to give the support team a sort of "SuperAdmin" so they can see the whole admin area.
- 0
- 2011-06-13
- Daniel Sachs
-
Ich sehe,dass Siemit der Verwendungnichteinverstanden sind,aber die Funktionfunktioniert undistnützlich,so dassichnicht verstehe,warum -1es.I see that you disagree with the usage, but the function works and is useful, so I do not understand why -1 it.
- 0
- 2011-06-13
- Daniel Sachs
-
Esgehörtnichtin einefunctions.php - wie leider viele Antworten hier - undes wirdfrüher oder späterbrechen.Außerdem verstößtesgegen die WordPress-Codierungsstandards.Bittenimm esnichtpersönlich.Meine Stimmeisteine Empfehlungfür den Leser.It doesn’t belong into a functions.php – like many answers here, unfortunately – and it **will** break sooner or later. Besides that, it violates the WordPress coding standards. Please, don’t take it personally. My vote is a recommendation for the reader.
- 0
- 2011-06-13
- fuxia
-
Natürlichnichts Persönliches,tosco.Wir alle versuchen zu helfen und zu lernen.Wir sind unsnichteinig,espassiert :)Of course, nothing personal, tosco. We all try to help and learn. We disagree, it happens :)
- 0
- 2011-06-13
- Daniel Sachs
-
@ Daniel Sachs Schauen Sie sich [diese Liste] an (https://gist.github.com/942518) undtauschen Sie "user_login"mit "role" (?) Aus.@Daniel Sachs Take a look at [this gist](https://gist.github.com/942518) and exchange `user_login` with `role`(?).
- 0
- 2011-06-13
- kaiser
-
@kaiser Dasistgroßartig,wenniches als Plugin odernichtgesetzte Menüsfür alle Administratoren verwenden wollte.Wiegesagt,diesermöglicht das Deaktivierenfürnureinen bestimmten Benutzermit ID1@kaiser This is great, if I wanted to use it as a plugin or unset menus for all admins. As i said, this allows to unset for just one specific user with ID1
- 0
- 2011-06-13
- Daniel Sachs
-
Wenn Sie sich das verknüpfte Plugin ansehen,können Sie Zugriffsgruppennach "was auchimmerein Benutzer anbietet (Anmeldename,Rolle,ID)"festlegen.Sichim Allgemeinen auf IDs zu verlassen,istein "nichtbewährtes Verfahren".Dasist alles,woraufich hinweisen wollte.If you look at the linked plugin, then it allows you to set access groups per "whatever a user offers (login name, role, ID)". Relying on IDs generally is a "not best practice" concept. That's all i wanted to point out.
- 1
- 2011-06-13
- kaiser
-
- 2011-08-19
Deaktiviert die Browser-Upgrade-Warnungin WordPress 3.2
//Disable browser upgrade warning in wordpress 3.2 function disable_browser_upgrade_warning() { remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' ); } add_action( 'wp_dashboard_setup', 'disable_browser_upgrade_warning' );
Disable browser upgrade warning in wordpress 3.2
//Disable browser upgrade warning in wordpress 3.2 function disable_browser_upgrade_warning() { remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' ); } add_action( 'wp_dashboard_setup', 'disable_browser_upgrade_warning' );
-
Reines Plugin-Material.Pure plugin material.
- 0
- 2011-08-19
- fuxia
-
@toscho Na und?Esfunktioniertimmernoch.Istesnicht?@toscho So what? Still its working. Isn't it?
- 0
- 2011-08-19
- Giri
-
Nichtnach dem Themenwechsel.Themen sindfür ** Frontends **.Not after switching themes. Themes are for **frontends**.
- 4
- 2011-08-19
- fuxia
-
- 2011-10-14
is_tree ()bedingte Funktion
/* Adapted from csstricks with addition of ancestors .... use = if(is_tree($id)) { // do stuff } ... Returns true if the page is = $id OR any of it's children OR descendants */ function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page $ancestors = get_post_ancestors($post); if(is_page()&&($post->post_parent==$pid||is_page($pid)||(in_array($pid,$ancestors)))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };
is_tree() conditional Function
/* Adapted from csstricks with addition of ancestors .... use = if(is_tree($id)) { // do stuff } ... Returns true if the page is = $id OR any of it's children OR descendants */ function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page $ancestors = get_post_ancestors($post); if(is_page()&&($post->post_parent==$pid||is_page($pid)||(in_array($pid,$ancestors)))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };
-
- 2011-12-04
Zeigt die Benutzer an,die diemeisten Kommentare ohne Plugin abgegeben haben
function top_comment_authors($amount = 5) { global $wpdb; $results = $wpdb->get_results(' SELECT COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url FROM '.$wpdb->comments.' WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1 GROUP BY comment_author_email ORDER BY comments_count DESC, comment_author ASC LIMIT '.$amount ); $output = "<ul>"; foreach($results as $result) { $output .= "<li>".$result->comment_author."</li>"; } $output .= "</ul>"; echo $output; }
Weitere Optionen,die Sie aufrufen können: $ result-> comment_author_email $ result-> comment_count $ result-> comment_author_url
Display the users that have submitted the most comments without a plugin
function top_comment_authors($amount = 5) { global $wpdb; $results = $wpdb->get_results(' SELECT COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url FROM '.$wpdb->comments.' WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1 GROUP BY comment_author_email ORDER BY comments_count DESC, comment_author ASC LIMIT '.$amount ); $output = "<ul>"; foreach($results as $result) { $output .= "<li>".$result->comment_author."</li>"; } $output .= "</ul>"; echo $output; }
Other options you can call: $result->comment_author_email $result->comments_count $result->comment_author_url
-
- 2010-09-13
Erhalten Sienach Möglichkeit dieechte IP-Adresse des Benutzers
Getestet am: Wordpress 3.0.1
Wenn Sieeinen Proxy oder Load Balancer verwenden,fügen Sie diesen Ihrer Datei wp-config.php oderfunctions.php
hinzu// Gets the user's real IP address $_SERVER['REMOTE_ADDR'] = getRealIpAddress(); function getRealIpAddress( $validate = true ) { if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $ip = trim($ips[count($ips) - 1]); } elseif ( isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ) { $ip = $_SERVER['HTTP_X_REAL_IP']; } elseif ( isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) { $ip = $_SERVER['HTTP_CLIENT_IP']; } else { $ip = $_SERVER['REMOTE_ADDR']; } if ( $validate && function_exists('filter_var') && filter_var($ip, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4, FILTER_FLAG_NO_PRIV_RANGE, FILTER_FLAG_NO_RES_RANGE)) ) return $ip; elseif ( $validate ) return long2ip(ip2long($ip)); return $ip; }
Get the Users Real IP Address whenever possible
Tested on: Wordpress 3.0.1
If you're using a proxy or load balancer, adding this to your wp-config.php file or functions.php
// Gets the user's real IP address $_SERVER['REMOTE_ADDR'] = getRealIpAddress(); function getRealIpAddress( $validate = true ) { if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $ip = trim($ips[count($ips) - 1]); } elseif ( isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ) { $ip = $_SERVER['HTTP_X_REAL_IP']; } elseif ( isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) { $ip = $_SERVER['HTTP_CLIENT_IP']; } else { $ip = $_SERVER['REMOTE_ADDR']; } if ( $validate && function_exists('filter_var') && filter_var($ip, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4, FILTER_FLAG_NO_PRIV_RANGE, FILTER_FLAG_NO_RES_RANGE)) ) return $ip; elseif ( $validate ) return long2ip(ip2long($ip)); return $ip; }
-
Wasmacht dasgenau?what does this do exactly?
- 1
- 2010-09-14
- NetConstructor.com
-
Wenn sichein Benutzer hintereinem Proxy oder Load Balancerbefindet,wird die IP-Adresse des Proxys oder Load Balancers angezeigt,wenn die IP-Adresse dieses Benutzersmit dem superglobalen $ _SERVER ['REMOTE_ADDR'] abgerufen wird.Der Proxy/lbgibt im Gegenzug die ursprüngliche IP-Adresse des Benutzersin die X-Forwarded-For X-Real-Ip- oder Client-Ip-Headerein (abhängig von der Proxy/lb-Konfiguration).Wenn Sie also kommentieren (oderposten,aber dasist weniger relevant),werdenin WP viele Benutzer von derselben IP-Adresse kommen.Diesbehebt das Problem,indem $ _SERVER ['REMOTE_ADDR'] durch die ursprüngliche IPersetzt wird.When a user is behind a proxy or load balancer, then anything that grabs that user's IP address using the superglobal $_SERVER['REMOTE_ADDR'] will see the proxy or load balancer's IP address. The proxy/lb in return puts the user's original IP address in the X-Forwarded-For X-Real-Ip, or Client-Ip headers (depending on the proxy/lb configuration). Thus, when commenting (or posting, but that's less relevant) WP will see a lot of users coming from the same IP address. This fixes that by replacing $_SERVER['REMOTE_ADDR'] with the original IP.
- 0
- 2010-09-19
- gabrielk
-
Diese sindeinfach auszutricksen,indem der HTTP_X_FORWARDED_FOR-Headermanuell zujeder Browseranforderung hinzugefügt wird.Mein Favoritistes,es auf 127.0.0.1 zu setzen,wodurch $ _SERVER ['REMOVE_ADDR']mit diesem Beispiel aufeinen leeren Wertgesetzt wird.Those are easy to trick by adding the HTTP_X_FORWARDED_FOR header manually into each browser request. My favorite is to set it 127.0.0.1 which will then set $_SERVER['REMOVE_ADDR'] to an empty value with that example.
- 0
- 2010-11-05
- hakre
-
- 2010-11-17
Automatisches Hinzufügen von Header-Bildern aus dem Verzeichnis
In der Standardeinstellung,diemit WordPressgeliefert wird,wirdein zusätzliches Themenmenü angezeigt,das aktiviert wird,mit dem Sieein zu verwendendes Header-Bild auswählen können. Innerhalb des Standard-Designcodes sind diese Bilderin der Dateifunctions.phpfest codiert. Mit demfolgenden Code kann WordPress automatischneue Bilderbasierend aufeinem bestimmten Header-Bild aufnehmen,das Sie direkt auf Ihrem Server (oderin Ihrem Themenordner)erstellen können.
Esenthält automatisch alle JPG- oder JPEG-Dateien. Jedes Bildmusseine zugehörige Miniaturbilddatei haben. Dies kannjedochnureine Kopie des Originalsmit einem anderen Namen undeinem Dateinamen sein,dermit "Miniaturbild"endenmuss. Der zugehörige Name wird als Beschreibungin den Einstellungenfür das Erscheinungsbild der Kopfzeilen verwendet,und Unterstriche werden automatisch durch Leerzeichenersetzt. (z. B. My_Header_Image_A.jpg,My_Header_Image_A=thumbnail.jpg wirdin einer Beschreibung automatischein "My Header Image A" angezeigt.)
if ($handle = opendir( TEMPLATEPATH . '/images/headers/') ) { $headers = array(); while (false !== ($file = readdir($handle))) { $pos = strrpos( $file, '.' ); if( $pos !== false && $pos > 0 ) { $file_name = substr( $file, 0, $pos ); if( strpos( $file_name, "-thumbnail" ) === false ) { $file_ext = substr( $file, $pos+1 ); $file_ext_low = strtolower( $file_ext ); if( $file_ext_low == "jpg" || $file_ext_low == "jpeg" ) { $headers[$file_name] = array ( 'url' => '%s/images/headers/' . $file, 'thumbnail_url' => '%s/images/headers/' . $file_name ."-thumbnail." . $file_ext, 'description' => __( str_replace( "_", " ", $file_name ), 'twentyten' ) ); } } } } closedir($handle); register_default_headers( $headers ); }
Automatically adding header images from directory location
Within the default them which comes with wordpress you will notice an additional theme menu which gets activated that lets you select a header image to be utilized. Within the default theme code these images are hardcoded into the functions.php file. The code below allows wordpress to automatically pick up new images based upon a specific header image directly you can create on your server (or within your themes folder).
It will automatically include any .jpg or .jpeg files. Every image must have a associating thumbnail file but this can just be a copy of the original with a different name with a file name that has to end in "-thumbnail". The associating name is used as the description in the headers appearance settings and underscores are automatically replaced with spaces. (e.g. My_Header_Image_A.jpg, My_Header_Image_A=thumbnail.jpg will have a description automatically presented a “My Header Image A”)
if ($handle = opendir( TEMPLATEPATH . '/images/headers/') ) { $headers = array(); while (false !== ($file = readdir($handle))) { $pos = strrpos( $file, '.' ); if( $pos !== false && $pos > 0 ) { $file_name = substr( $file, 0, $pos ); if( strpos( $file_name, "-thumbnail" ) === false ) { $file_ext = substr( $file, $pos+1 ); $file_ext_low = strtolower( $file_ext ); if( $file_ext_low == "jpg" || $file_ext_low == "jpeg" ) { $headers[$file_name] = array ( 'url' => '%s/images/headers/' . $file, 'thumbnail_url' => '%s/images/headers/' . $file_name ."-thumbnail." . $file_ext, 'description' => __( str_replace( "_", " ", $file_name ), 'twentyten' ) ); } } } } closedir($handle); register_default_headers( $headers ); }
-
- 2011-03-21
Entfernen Sie den Link "Kommentare" aus der Admin-Leiste,wenn der Kommentarstatusgeschlossenist.
Sie können den Standardkommentarstatus auf "geschlossen" setzen,der Kommentarlinkbleibtjedocherhalten.Fügen Sieeinfach Folgendesin Ihre Datei
functions.php
ein,umesbasierend auf der Bedingung zuentfernen.Bietet 2 verschiedene Ansätze./** * Disable 'Comments' link if default status is _closed_ */ function remove_comments() { $default_comment_status = get_option( 'default_comment_status' ); if ( $default_comment_status == 'closed' ) { remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 50 ); // optional solution using the WP_Admin_Bar class from /wp-includes/class-wp-admin-bar.php # global $wp_admin_bar; # $wp_admin_bar->remove_menu( 'comments' ); } else { return; } }
Remove "Comments" link from admin bar if comment status is closed
You can set the default comment status to 'closed', but the comments link will stay. Simply drop the following into your
functions.php
file to get rid of it based on the condition. Offers 2 different approaches./** * Disable 'Comments' link if default status is _closed_ */ function remove_comments() { $default_comment_status = get_option( 'default_comment_status' ); if ( $default_comment_status == 'closed' ) { remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 50 ); // optional solution using the WP_Admin_Bar class from /wp-includes/class-wp-admin-bar.php # global $wp_admin_bar; # $wp_admin_bar->remove_menu( 'comments' ); } else { return; } }
-
- 2011-11-30
Fügt WP_NAV_MENUSeine benutzerdefinierte Dropdown-Option hinzu,mit der der Benutzerfürjeden Menüpunkt
eine vordefinierte CSS-Klasse auswählen kann<?php function menu_item_class_select(){ global $pagenow; if ($pagenow == "nav-menus.php"){ ?> <script> jQuery(document).ready(function(){ function create_dd(v){ //create dropdown var dd = jQuery('<select class="my_class"></select>'); //create dropdown options //array with the options you want var classes = ["","class1","class2","class3"]; jQuery.each(classes, function(i,val) { if (v == val){ dd.append('<option value="'+val+'" selected="selected">'+val+'</option>'); }else{ dd.append('<option value="'+val+'">'+val+'</option>'); } }); return dd; } jQuery(".edit-menu-item-classes").each(function() { //add dropdown var t = create_dd(jQuery(this).val()); jQuery(this).before(t); //hide all inputs jQuery(this).css("display","none"); }); //update input on selection jQuery(".my_class").bind("change", function() { var v = jQuery(this).val(); var inp = jQuery(this).next(); inp.attr("value",v); }); }); </script> <?php } } add_action('admin_footer','menu_item_class_select'); ?>
Adds a custom dropdown option to WP_NAV_MENUS where the user can select a predefined css class for each menu item
<?php function menu_item_class_select(){ global $pagenow; if ($pagenow == "nav-menus.php"){ ?> <script> jQuery(document).ready(function(){ function create_dd(v){ //create dropdown var dd = jQuery('<select class="my_class"></select>'); //create dropdown options //array with the options you want var classes = ["","class1","class2","class3"]; jQuery.each(classes, function(i,val) { if (v == val){ dd.append('<option value="'+val+'" selected="selected">'+val+'</option>'); }else{ dd.append('<option value="'+val+'">'+val+'</option>'); } }); return dd; } jQuery(".edit-menu-item-classes").each(function() { //add dropdown var t = create_dd(jQuery(this).val()); jQuery(this).before(t); //hide all inputs jQuery(this).css("display","none"); }); //update input on selection jQuery(".my_class").bind("change", function() { var v = jQuery(this).val(); var inp = jQuery(this).next(); inp.attr("value",v); }); }); </script> <?php } } add_action('admin_footer','menu_item_class_select'); ?>
-
- 2011-12-19
Entfernen Sie die Menüelemente der WordPress 3.3-Admin-Leiste
function dashboard_tweaks() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->remove_menu('feedback'); $wp_admin_bar->remove_menu('view-site'); } add_action( 'wp_before_admin_bar_render', 'dashboard_tweaks' );
Referenz: http://pastebin.com/Wrk0JPxw
Remove WordPress 3.3 Admin Bar Menu Items
function dashboard_tweaks() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->remove_menu('feedback'); $wp_admin_bar->remove_menu('view-site'); } add_action( 'wp_before_admin_bar_render', 'dashboard_tweaks' );
Reference: http://pastebin.com/Wrk0JPxw
-
- 2010-11-04
Standardkategorie von öffentlichen Seiten ausschließen
Schließt die Standardkategorie von der Vorderseite der Website aus.
Code schließt den Administrationsbereich aus,andernfalls haben Sie keine Möglichkeit,Beiträge zu verwalten,die der Standardkategorie zugewiesen sind.add_filter( 'list_terms_exclusions', 'exclude_default_cat' ); function exclude_default_cat( $exclusions ) { if( !is_admin() ) $exclusions .= "AND t.term_id != " . get_option( 'default_category' ) . " "; return $exclusions; }
Exclude default category from public pages
Excludes the default category from the front-facing side of the website.
Code excludes the admin area, else you'll have no way to manage posts assigned with the default category.add_filter( 'list_terms_exclusions', 'exclude_default_cat' ); function exclude_default_cat( $exclusions ) { if( !is_admin() ) $exclusions .= "AND t.term_id != " . get_option( 'default_category' ) . " "; return $exclusions; }
-
- 2010-12-03
Anzeigen von Informationenfür angemeldete Benutzer
if ( is_user_logged_in() ) { }
funktioniertnichtin der Dateifunctions.php.Sie können diesen Code verwenden:
if ( !function_exists('is_user_logged_in') ) : function is_user_logged_in() { $user = wp_get_current_user(); if ( $user->id == 0 ){ // This section if user is not logged in } else { // This section if user is logged in } } endif;
Displaying information for logged in users
if ( is_user_logged_in() ) { }
is not working in functions.php file. You can use this code:
if ( !function_exists('is_user_logged_in') ) : function is_user_logged_in() { $user = wp_get_current_user(); if ( $user->id == 0 ){ // This section if user is not logged in } else { // This section if user is logged in } } endif;
-
`if (! current_user_can ('read'))` sollte Gästefangen (dhnicht angemeldete Benutzer) ..`if( !current_user_can('read') )` should catch guests (ie. non-logged in users) ..
- 0
- 2010-12-07
- t31os
-
Ich habeesgeradegetestet und `is_user_logged_in ()` scheintin `functions.php`gut zufunktionieren? .. Hintergrundinformationen darüber,warumesnicht soll?I just tested it and `is_user_logged_in()` seems to work just fine in `functions.php`?.. Any background info on why it's not supposed to?
- 2
- 2011-01-26
- Rarst
-
- 2011-06-13
Benutzerdefinierte Logosfür Anmeldeseite und Administrator
/*-----------------------------------------------------------------------------------*/ /* Custom logos /*-----------------------------------------------------------------------------------*/ function custom_admin_logo() { echo ' <style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/path/to/images/admin-logo.png) !important; } </style> '; } add_action('admin_head', 'custom_admin_logo'); function custom_login_logo() { echo '<style type="text/css"> h1 a { background-image:url('.get_bloginfo('template_directory').'/path/to/images/login-logo.png) !important; } </style>'; } add_action('login_head', 'custom_login_logo');
Custom Logos for Login page and Admin
/*-----------------------------------------------------------------------------------*/ /* Custom logos /*-----------------------------------------------------------------------------------*/ function custom_admin_logo() { echo ' <style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/path/to/images/admin-logo.png) !important; } </style> '; } add_action('admin_head', 'custom_admin_logo'); function custom_login_logo() { echo '<style type="text/css"> h1 a { background-image:url('.get_bloginfo('template_directory').'/path/to/images/login-logo.png) !important; } </style>'; } add_action('login_head', 'custom_login_logo');
-
Bitte werfen Sieeinen Blick auf [diesen Kern] (https://gist.github.com/671743).Esgibt nochbessere Optionen alsim Kerngezeigt.Sie können auch versuchen,am Trac-Ticketteilzunehmen (Linkim Haupt-Plugin-Header).Please take a look at [this gist](https://gist.github.com/671743). There are even better options than shown in the gist. You could also try to participate on the trac ticket (link in gist plugin header).
- 2
- 2011-06-13
- kaiser
-
- 2011-06-13
Entfernen Sie den Administrator (Benutzer Nr. 1) aus der Benutzerliste
function your_pre_user_query($user_search) { $user = wp_get_current_user(); if ($user->ID!=1) { global $wpdb; $user_search->query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.ID<>1",$user_search->query_where); } } add_action('pre_user_query','your_pre_user_query');
Remove Admin (User #1) from User list
function your_pre_user_query($user_search) { $user = wp_get_current_user(); if ($user->ID!=1) { global $wpdb; $user_search->query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.ID<>1",$user_search->query_where); } } add_action('pre_user_query','your_pre_user_query');
-
Nochmals: Benutzer 1istmöglicherweise kein Administrator.Siehe [Rollen und Funktionen] (http://codex.wordpress.org/Roles_and_Capabilities).Again: user 1 may be a non-admin. See [Roles and Capabilities](http://codex.wordpress.org/Roles_and_Capabilities).
- 0
- 2011-06-13
- fuxia
-
Esistein Beispiel.Außerdemistin Standardinstallationen Benutzer 1 Admin - dererste Benutzer,dererstellt wurde.Deshalb habeichbetont (Benutzer # 1)It's an example. Plus in default installations the user 1 is Admin - the first user created. This is why I emphasized (User #1)
- 0
- 2011-06-13
- Daniel Sachs
-
Esistein Beispiel,das zeigt,wie Sienichtnach Verwaltungsfunktionen suchen.Sie sollten diesen Codenicht aufeinerechten Website verwenden.It is an example showing how not to check for administrative capabilities. You should not use this code in a real website.
- 0
- 2011-06-13
- fuxia
-
Genau.Dieser Codeprüftnichtnach Funktionen,sondernnachbestimmten Benutzern.Dieser Code hatnichtsmit Funktionen zutun,undich habenirgendwo Funktionenerwähnt.Ich verstehenicht,warum diesnicht auf Produktionsstätten verwendet werden kann.Exactly. This code doesn't check for capabilities, toscho, but for specific user. This code has nothing to do with capabilities and I haven't mentioned capabilities anywhere. I don't see why this can not be used on production sites.
- 0
- 2011-06-13
- Daniel Sachs
-
@ Daniel Sachs Wenn Sienach demersten hinzugefügten Administrator suchen,überprüfen Siebitte zuerst die Rollen aller Benutzer,sortieren Sie sie dannnachihrer ID undnehmen Sie dieerste.Wie @toscho sagte: Derzeitistes "wiemanesnichtmachen sollte".Gründe: a) Dertatsächliche Administratoristmöglicherweisenicht derjenigemit derniedrigsten ID. B) Wennjemand anderes daran arbeiten würde,würdeer/sienichtin einem Themanach dieser Funktionalität suchen.@Daniel Sachs If you're searching for the first ever added administrator, please check the roles of all users first, then sort them by their ID and take the first one. As @toscho said: Currently it's "how you should not do it example". Reasons: a) the actual Admin might not be the one with the lowest ID b) If someone else would work on this, she/he wouldn't search for this functionality in a theme.
- 0
- 2011-06-13
- kaiser
-
- 2011-09-14
Attribute der angegebenen Miniaturansicht abrufen
Verwenden Sie diese Funktionmit der Schleife,um Breite,Höhe und URLeines Miniaturbilds zubestimmen. Sehrpraktisch,umein Miniaturbild als Hintergrundelement über Inline-CSS zuzuweisen.
/** * GET THUMBNAIL ATTRIBUTES * * Fetches width, heigth and URI of a thumbnail. * * @author Philip Downer <[email protected]> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version v1.0 * * @param string $return Accepts 'path', 'width', or 'height'. * @param string $size The thumbnail size corresponding to {@link add_image_size() WP core function}. * @return mixed Returns the requested info, or if no 'Featured Image' assigned, returns 'false'. */ function get_thumb_attr($return,$size='thumbnail') { global $post; if (has_post_thumbnail($post->ID)) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'intro'); if ( $return == 'path' ) { return $thumb[0]; } if ( $return == 'width' ) { return $thumb[1]; } if ( $return == 'height' ) { return $thumb[2]; } } else { return false; } }//end function
Get Attributes of Given Thumbnail
Use this function with the loop to determine width, height and URL of a thumbnailed image. Very handy for assigning a thumbnailed image as a background element via inline CSS.
/** * GET THUMBNAIL ATTRIBUTES * * Fetches width, heigth and URI of a thumbnail. * * @author Philip Downer <[email protected]> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version v1.0 * * @param string $return Accepts 'path', 'width', or 'height'. * @param string $size The thumbnail size corresponding to {@link add_image_size() WP core function}. * @return mixed Returns the requested info, or if no 'Featured Image' assigned, returns 'false'. */ function get_thumb_attr($return,$size='thumbnail') { global $post; if (has_post_thumbnail($post->ID)) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'intro'); if ( $return == 'path' ) { return $thumb[0]; } if ( $return == 'width' ) { return $thumb[1]; } if ( $return == 'height' ) { return $thumb[2]; } } else { return false; } }//end function
-
- 2011-11-17
Geben Sie den Inhalteines Widgets außerhalb des Kontextseiner Seitenleistemit seiner ID aus. Das Umbrechen vor/nach HTMListnichtenthalten. Siemüssen die spezifische ID des Widgets kennen,nach dem Sie suchen (z. B. 'text-5').
function widget_contents($id) { list($type,$number) = explode('-',$id); global $wp_registered_widgets; $wp_registered_widgets[$id]['callback'][0]->display_callback(array('widget_id'=>$id),$number); }
Sie könneneinen Blick auf die Ausgabe von wp_get_sidebars_widgets () werfen,wenn Sie sichnicht sicher sind,welche ID Siegenaubenötigen.
Ein vollständigeres Beispiel aus /wp-includes/widgets.php unter der Funktion dynamic_sidebar () :
function render_widget($id) { global $wp_registered_widgets; $params = array_merge( array( array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ), (array) $wp_registered_widgets[$id]['params'] ); $classname_ = ''; foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { if ( is_string($cn) ) $classname_ .= '_' . $cn; elseif ( is_object($cn) ) $classname_ .= '_' . get_class($cn); } $classname_ = ltrim($classname_, '_'); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); if ( is_callable($wp_registered_widgets[$id]['callback']) ) call_user_func_array($wp_registered_widgets[$id]['callback'], $params); }
Output the contents of a widget outside the context of a sidebar using it's ID. The wrapping before/after HTML is not included. You need to know the specific ID of the widget you're angling for (ie 'text-5').
function widget_contents($id) { list($type,$number) = explode('-',$id); global $wp_registered_widgets; $wp_registered_widgets[$id]['callback'][0]->display_callback(array('widget_id'=>$id),$number); }
You can peek at the output of wp_get_sidebars_widgets() if you aren't sure of the precise ID you need.
A more complete example lifted from /wp-includes/widgets.php under the dynamic_sidebar() function:
function render_widget($id) { global $wp_registered_widgets; $params = array_merge( array( array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ), (array) $wp_registered_widgets[$id]['params'] ); $classname_ = ''; foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { if ( is_string($cn) ) $classname_ .= '_' . $cn; elseif ( is_object($cn) ) $classname_ .= '_' . get_class($cn); } $classname_ = ltrim($classname_, '_'); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); if ( is_callable($wp_registered_widgets[$id]['callback']) ) call_user_func_array($wp_registered_widgets[$id]['callback'], $params); }
-
Doh.Die vieleinfachere Methode wäre die Verwendung von "the_widget ()" http://codex.wordpress.org/Function_Reference/the_widgetDoh. The much simpler method would be to use `the_widget()` http://codex.wordpress.org/Function_Reference/the_widget
- 0
- 2012-02-08
- dalethedeveloper
-
- 2011-12-04
Benutzerdefinierte Smilies (Plugin)
/** * Smilies. */ function filter_smilies_src($img_src, $img, $siteurl) { return plugins_url('', __FILE__) . '/img/smilies/' . $img; } add_filter('smilies_src', 'filter_smilies_src', 1, 10);
Benutzerdefinierte Smilies (Thema)
/** * Smilies. */ function filter_smilies_src($img_src, $img, $siteurl) { return get_bloginfo('stylesheet_directory') . '/images/smilies/' . $img; } add_filter('smilies_src', 'filter_smilies_src', 1, 10);
Custom smilies (plugin)
/** * Smilies. */ function filter_smilies_src($img_src, $img, $siteurl) { return plugins_url('', __FILE__) . '/img/smilies/' . $img; } add_filter('smilies_src', 'filter_smilies_src', 1, 10);
Custom smilies (theme)
/** * Smilies. */ function filter_smilies_src($img_src, $img, $siteurl) { return get_bloginfo('stylesheet_directory') . '/images/smilies/' . $img; } add_filter('smilies_src', 'filter_smilies_src', 1, 10);
-
- 2012-02-03
Taxonomie-Tags abfragen
Eine zwischengespeicherte Abfrage,dieeine
get_tags()
-ähnliche HTML-Zeichenfolge aller Tagsfüreinen bestimmten Taxonomy-Parameter ausgibt,der standardmäßigeine Kategorie ist. Sie können$where_slug
und$where_tax
verwenden,um Post-Tagsnacheiner anderen Taxonomiefiltern zu lassen. SQLgetestetfür WP 3.1bis WP 3.3.1.function tags_by_other_taxonomy($where_slug,$where_tax = 'category',$bust_cache = false) { $cache_key = "{$where_slug}:{$where_tax}"; $cache = get_transient('tags_by_other_taxonomy'); $html = ''; if( true !== $bust_cache and false !== $cache and isset($cache[$cache_key]) and !empty($cache[$cache_key]) ) { $html = $cache[$cache_key]; } else { global $wpdb; $cat_id = $wpdb->get_var("SELECT tt.term_taxonomy_id FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id WHERE t.slug = '{$where_slug}' AND tt.taxonomy = '{$where_tax}' LIMIT 1"); if( !empty($cat_id) ) { $cat_posts = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships tr inner join $wpdb->posts p ON p.ID = tr.object_id WHERE term_taxonomy_id = {$cat_id} AND p.post_status = 'publish' AND p.post_type = 'post'"); if( count($cat_posts) ) { $tags = $wpdb->get_results("SELECT DISTINCT t.name,t.slug FROM $wpdb->term_taxonomy tt INNER JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id INNER JOIN $wpdb->terms t ON t.term_id = tt.term_id WHERE tt.taxonomy = 'post_tag' and tr.object_id IN (".implode(',',$cat_posts) .')'); $html = '<ul class="post-tags-'.$where_slug.'">'; if( count($tags) ) { foreach($tags as $tag) $html .= '<li><a href="/tag/'.$tag->slug.'/" title="Posts tagged with '.$tag->name.'">'.$tag->name.'</a></li>'; } $html .= '</ul>'; if( !is_array($cache) ) $cache = array(); $cache[$cache_key] = $html; set_transient('sc_cross_tax', $cache, 86400); } } } echo $html; }
Rufen Siebeispielsweise alle Tagsfür veröffentlichte Beiträge in der Kategorie Nachrichten ab:
<?php echo tags_by_other_taxonomy('news'); ?>
Cross Taxonomy Tags Query
A cached query that outputs a
get_tags()
like HTML string of all tags for a given Taxonomy parameter defaulting to a Category. You can use$where_slug
and$where_tax
to get post tags filtered by any other taxonomy. SQL tested for WP 3.1 to WP 3.3.1.function tags_by_other_taxonomy($where_slug,$where_tax = 'category',$bust_cache = false) { $cache_key = "{$where_slug}:{$where_tax}"; $cache = get_transient('tags_by_other_taxonomy'); $html = ''; if( true !== $bust_cache and false !== $cache and isset($cache[$cache_key]) and !empty($cache[$cache_key]) ) { $html = $cache[$cache_key]; } else { global $wpdb; $cat_id = $wpdb->get_var("SELECT tt.term_taxonomy_id FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id WHERE t.slug = '{$where_slug}' AND tt.taxonomy = '{$where_tax}' LIMIT 1"); if( !empty($cat_id) ) { $cat_posts = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships tr inner join $wpdb->posts p ON p.ID = tr.object_id WHERE term_taxonomy_id = {$cat_id} AND p.post_status = 'publish' AND p.post_type = 'post'"); if( count($cat_posts) ) { $tags = $wpdb->get_results("SELECT DISTINCT t.name,t.slug FROM $wpdb->term_taxonomy tt INNER JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id INNER JOIN $wpdb->terms t ON t.term_id = tt.term_id WHERE tt.taxonomy = 'post_tag' and tr.object_id IN (".implode(',',$cat_posts) .')'); $html = '<ul class="post-tags-'.$where_slug.'">'; if( count($tags) ) { foreach($tags as $tag) $html .= '<li><a href="/tag/'.$tag->slug.'/" title="Posts tagged with '.$tag->name.'">'.$tag->name.'</a></li>'; } $html .= '</ul>'; if( !is_array($cache) ) $cache = array(); $cache[$cache_key] = $html; set_transient('sc_cross_tax', $cache, 86400); } } } echo $html; }
For example, get all tags for Published Posts in the news Category slug:
<?php echo tags_by_other_taxonomy('news'); ?>
-
- 2010-09-09
Positionieren Sie den WYSIWYG-Editor über JQUERY
neuGetestet am: Wordpress 3.0.1
Mit diesem Code können Siebestimmte Meta-Felderentfernen,die WordPress standardmäßig zu den Bildschirmen POST und PAGES hinzufügt.
// REPOSITION WYSIWYG EDITOR THROUGH JQUERY add_action('admin_head','admin_head_hook'); function admin_head_hook() { ?><style type="text/css"> #postdiv.postarea, #postdivrich.postarea { margin:0; } #post-status-info { line-height:1.4em; font-size:13px; } .custom-wysiwyg-editor-container { margin:2px 6px 6px 6px; } #ed_toolbar { display:none; } #postdiv #ed_toolbar, #postdivrich #ed_toolbar { display:block; } </style><?php } add_action('admin_footer','admin_footer_hook'); function admin_footer_hook() { ?><script type="text/javascript"> jQuery('#postdiv, #postdivrich').prependTo('.custom-wysiwyg-editor-container'); </script><?php }
Reposition the WYSIWYG Editor through JQUERY
Tested on: Wordpress 3.0.1
This code will allow you to remove specific meta boxes which wordpress adds by default to the POST and PAGES screens.
// REPOSITION WYSIWYG EDITOR THROUGH JQUERY add_action('admin_head','admin_head_hook'); function admin_head_hook() { ?><style type="text/css"> #postdiv.postarea, #postdivrich.postarea { margin:0; } #post-status-info { line-height:1.4em; font-size:13px; } .custom-wysiwyg-editor-container { margin:2px 6px 6px 6px; } #ed_toolbar { display:none; } #postdiv #ed_toolbar, #postdivrich #ed_toolbar { display:block; } </style><?php } add_action('admin_footer','admin_footer_hook'); function admin_footer_hook() { ?><script type="text/javascript"> jQuery('#postdiv, #postdivrich').prependTo('.custom-wysiwyg-editor-container'); </script><?php }
-
- 2010-09-09
Fehlende Tags aus dem WYSIWYG-Editor automatisch schließen
Getestet am: Wordpress 3.0.1
Dieser Code schließt automatisch allefehlenden Tags,wenn Sie den WYSIWYG-Editor verwenden.
// AUTOMATICALLY CLEAN UP HTML WYSIWYG EDITOR BY CLOSING MISSING TAGS function clean_bad_content($bPrint = false) { global $post; $szPostContent = $post->post_content; $szRemoveFilter = array("~<p[^>]*>\s?</p>~", "~<a[^>]*>\s?</a>~", "~<font[^>]*>~", "~<\/font>~", "~style\=\"[^\"]*\"~", "~<span[^>]*>\s?</span>~"); $szPostContent = preg_replace($szRemoveFilter, '', $szPostContent); $szPostContent = apply_filters('the_content', $szPostContent); if ($bPrint == false) return $szPostContent; else echo $szPostContent; }
Automatically close missing tags from the WYSIWYG editor
Tested on: Wordpress 3.0.1
This code will automatically close any missing tags when using the WYSIWYG editor.
// AUTOMATICALLY CLEAN UP HTML WYSIWYG EDITOR BY CLOSING MISSING TAGS function clean_bad_content($bPrint = false) { global $post; $szPostContent = $post->post_content; $szRemoveFilter = array("~<p[^>]*>\s?</p>~", "~<a[^>]*>\s?</a>~", "~<font[^>]*>~", "~<\/font>~", "~style\=\"[^\"]*\"~", "~<span[^>]*>\s?</span>~"); $szPostContent = preg_replace($szRemoveFilter, '', $szPostContent); $szPostContent = apply_filters('the_content', $szPostContent); if ($bPrint == false) return $szPostContent; else echo $szPostContent; }
-
Nur um Sie wissen zu lassen,gibt eseine Möglichkeit,diesin WordPress selbst zutun.IT kannnützlich sein,wennesfürmehrere Benutzer unabhängig vonihrer Einstellungerzwungen werdenmuss.Aberich würde stattdessen das Speichern dieser Einstellungerzwingen.Just to let you know there is an option of doing that in WordPress itself. IT can be useful if one needs to force it for multiple users irrespective of their setting. But I would force saving that setting instead.
- 0
- 2011-04-20
- Ashfame
-
- 2011-01-28
Entfernen Sie die
role="search"
-Attributefürget_search_form()
function remove_role_search($role) { $result = array(); preg_match_all('|role="[^"]*"|U', $role, $result); foreach ($result[0] as $role_tag) { $role = str_replace($role_tag, '', $role); } return $role; } add_filter('get_search_form', 'remove_role_search');
Remove
role="search"
attributes forget_search_form()
function remove_role_search($role) { $result = array(); preg_match_all('|role="[^"]*"|U', $role, $result); foreach ($result[0] as $role_tag) { $role = str_replace($role_tag, '', $role); } return $role; } add_filter('get_search_form', 'remove_role_search');
-
- 2011-02-23
Fügen Sieeinen Anmeldelink zu wp_nav_menu
hinzu//ADD LOGIN LINK TO MENU add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) { $loginoutlink = wp_loginout('index.php', false); $items .= '<li>'. $loginoutlink .'</li>'; return $items; }
Add a Login Link to wp_nav_menu
//ADD LOGIN LINK TO MENU add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) { $loginoutlink = wp_loginout('index.php', false); $items .= '<li>'. $loginoutlink .'</li>'; return $items; }
-
Verwenden Sie keine Ausgabepufferung.`wp_loginout ()` hateinen zweiten Parameter `$echo`,um Ihnen das Leben zuerleichtern.Do not use output buffering. `wp_loginout()` has a second parameter `$echo` to make your life easier.
- 3
- 2011-02-23
- fuxia
-
- 2011-05-12
Ändern des Menünamens "Beiträge"im Administratornach Ihren Wünschen (z. B. "Artikel")
// hook the translation filters add_filter('gettext','change_post_to_article'); add_filter('ngettext','change_post_to_article'); function change_post_to_article( $translated ) { $translated = str_ireplace('Post','Article',$translated );// ireplace is PHP5 only return $translated; }
Credits an smashingmagazine.com
Changing "Posts" menu name in admin to whatever you wish (e.g. "Articles")
// hook the translation filters add_filter('gettext','change_post_to_article'); add_filter('ngettext','change_post_to_article'); function change_post_to_article( $translated ) { $translated = str_ireplace('Post','Article',$translated );// ireplace is PHP5 only return $translated; }
Credits to smashingmagazine.com
-
- 2011-09-14
Menüelement "Linksentfernen"
Vielemeiner WordPress-Installationenerfordernnicht,dass Benutzer Zugriff auf den Menüpunkt "Links" haben.Diese Funktionentferntes aus der Ansicht.
add_action( 'admin_menu', 'custom_admin_menu' ); function custom_admin_menu() { global $menu; // var_dump($menu); // use this to identify the key for the menu item you want to remove unset( $menu[15] ); //key 15 is links if ( !current_user_can('manage_options') ) { unset( $menu[75] ); } //key 75 is tools ... but only for non super admins }
Remove Links Menu Item
Many of my WordPress installs don't require that users have access to the 'Links' menu item. This function removes it from view.
add_action( 'admin_menu', 'custom_admin_menu' ); function custom_admin_menu() { global $menu; // var_dump($menu); // use this to identify the key for the menu item you want to remove unset( $menu[15] ); //key 15 is links if ( !current_user_can('manage_options') ) { unset( $menu[75] ); } //key 75 is tools ... but only for non super admins }
-
- 2011-09-14
Nachricht "Upgradejetzt deaktivieren"für Nicht-Administratoren
Ichbin eigentlichein großer Fan davon,diesen Code NICHT zu verwenden.Stattdessenmöchteich Kunden liebererlauben,ihreeigenen WordPress-Installationen zu aktualisieren.Dies hilft,die Site auf demneuesten Stand zu halten und zwingtmich,besseren Code zu schreiben.
if ( !current_user_can( 'manage_options' ) ) { add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }
Disable Upgrade Now Message for Non-Administrators
I'm actually a big fan of NOT using this code. Instead, I prefer to allow customers to update their own WordPress installs. This helps keep the site up-to-date and forces me to write better code.
if ( !current_user_can( 'manage_options' ) ) { add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }
-
- 2011-12-04
Fügen Sie demnächsten und vorherigen Linkeine benutzerdefinierte Klasse hinzu
add_filter('next_posts_link_attributes', 'posts_link_attributes'); add_filter('previous_posts_link_attributes', 'posts_link_attributes'); function posts_link_attributes(){ return 'class="styled-button"'; }
Add a custom class to the next and previous links
add_filter('next_posts_link_attributes', 'posts_link_attributes'); add_filter('previous_posts_link_attributes', 'posts_link_attributes'); function posts_link_attributes(){ return 'class="styled-button"'; }
-
- 2011-12-04
Fügen Sie automatischein verstecktesbenutzerdefiniertes Feld hinzu und ordnen Sieeinem Beitrageinen Wert zu,wenn der Beitrag veröffentlicht wird.
add_action('publish_page', 'add_custom_field_automatically'); add_action('publish_post', 'add_custom_field_automatically'); function add_custom_field_automatically($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, 'field-name', 'custom value', true); } }
Automatically add a hidden custom field and associating value to a post when the post is published
add_action('publish_page', 'add_custom_field_automatically'); add_action('publish_post', 'add_custom_field_automatically'); function add_custom_field_automatically($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, 'field-name', 'custom value', true); } }
-
- 2011-12-17
Benutzerdefinierte Beitragstypen zur Archivseite hinzufügen
function namespace_add_custom_types( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'your-custom-post-type-here' )); return $query; } } add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
Add custom post types to archives page
function namespace_add_custom_types( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'your-custom-post-type-here' )); return $query; } } add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
-
- 2010-12-28
Rufen Siebloginfomit dem Shortcode auf ...
function digwp_bloginfo_shortcode($atts) { extract(shortcode_atts(array( 'key' => '', ), $atts)); return get_bloginfo($key); } add_shortcode('bloginfo', 'digwp_bloginfo_shortcode');
Verwendung:
[bloginfo key='name']
Call bloginfo using shortcode...
function digwp_bloginfo_shortcode($atts) { extract(shortcode_atts(array( 'key' => '', ), $atts)); return get_bloginfo($key); } add_shortcode('bloginfo', 'digwp_bloginfo_shortcode');
Usage:
[bloginfo key='name']
-
Können Sieeinige Beispiele hinzufügen,wo diesnützlich sein könnte?Can you add some examples of where this could be useful?
- 0
- 2020-02-01
- Peter Mortensen
Wiebei vielen anderen,die diesen Beitragjetzt anzeigen,habeich verschiedene Blogs,Foren und Diskussionsgruppengelesen,ummeine WordPress-Kenntnisse zuerlernen und zu verbessern. In den letzten 12 Monaten hatteich die Mission,die Verwendung von Plugins durch das Hinzufügen von Code zumeiner Datei
functions.php
zuersetzen.Obwohlich völlig damiteinverstandenbin,dass Pluginsin vielen Situationen sehrnützlich sind,hatmeine Erfahrunggezeigt,dassin 90% der Anwendungsfälle,obwohlein Plugin vorhanden sein könnte,dietatsächliche Verwendung unnötige Komplikationen und Kompatibilitätsprobleme verursachen kann. Zusätzlich haben solche Pluginsin vielen Fällen Menüs und andere Admin-Elemente hinzugefügt,dieichnichtmöchte oderbrauche.
Meistens habeichfestgestellt,dassich durch die Analyse des Plugin-Codes dengewünschten Codeentfernen undin meine
functions.php
fest codieren konnte. Dadurcherhieltichgenau die Funktionalität,dieichbenötigte,ohne unnötige Elementeeinfügen zumüssen.Der Zweck dieses Beitragsist alsomein Versuch,Sie,den Leser/Administrator/Entwickler,dazu zubewegen,mir und anderen hier alle Codebitsmitzuteilen,die Sienützlichfinden und die zur
function.php
-Datei zum Erweitern oder Verbessern von WordPress ohne Verwendungeines Plugins.Wenn Sie hiereine Antwort senden,geben Siebitte jedem Codebiteinen Titel. Lassen Sie uns wissen,obmit welcher Version von WordPress Sie kompatibel sind,geben Sie die Beschreibung an,die Ihrer Meinungnach die Funktion ambestenbeschreibt,undfügen Sie (falls zutreffend)einen Link hinzu zu dem ursprünglichen Plugin oder der Quelle,in der Sie die Informationengefunden haben.
Ichfreuemich auf alle Ihre Antworten und werdenatürlich ständigmeine eigenenneuen Funde hinzufügen,wennich siefinde.
Bitte stimmen Sie über die Frage und alle Antworten ab,die Sienützlichfinden,indem Sie auf den Pfeil up auf der linken Seite der Frage oder Antwort klicken.