Vyladění nové instalace WordPressu

Nastavení .htaccess

Zabezpeční souboru wp-config.php


<files wp-config.php>
order allow,deny
deny from all
</files>

Adresa vždy bez www


RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^www.domena.cz
RewriteRule (.*) http://domena.cz/$1 [R=301,QSA,L]

Adresa vždy s www


RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^domena.cz
RewriteRule (.*) http://www.domena.cz/$1 [R=301,QSA,L]

Zákaz výpisu obsahu adresářů


Options -Indexes

Odstranění „rubriky“ z url


RewriteRule ^category/(.+)$ http://www.domena.cz/$1 [R=301,L]

(ev. použijeme plugin „No category base“:45)

Robots.txt

Zákaz přístupu do adresářů WordPressu robotům a uvedení odkazu na sitemap


User-agent: *
Disallow: /cgi-bin/
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/
Disallow: /trackback/
Disallow: /xmlrpc.php
Disallow: /wp-

Sitemap: http://domena.cz/sitemap.xml

Pro vytvoření sitemapy použijeme plugin „Google XML Sitemaps“:219

Nastavení „user-friendly“ odkazů

Nastavení > Trvalé odkazy > Vlastní struktura: /%postname%/

Vytvoření a odkaz na favicon

1. Vytvoříme *favicon.ico* (např. zde nebo zde
3. Zkopírujeme ho do rootu našeho blogu
2. Umístíme do hlavičky v souboru *header.php*


<link rel="shortcut icon" href="<?php bloginfo('url'); ?>/favicon.ico" />

Blocks script injections

The following code blocks script injections and any attempts to modify the PHP GLOBALS and _REQUEST variables.


Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

Hot-linking protection


RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

Odstranění verze WordPressu

Paste the following lines of code in the functions.php file of your theme:


function wp_remove_version() {
return '';
}
add_filter('the_generator', 'wp_remove_version');

Disable eval:

This can be done with a PHP Extension called Suhosin; the Suhosin configuration can be edited within your php.ini file.


suhosin.executor.disable_eval = On

Další doporučená nastavení souboru .htacess
6 .htaccess Tricks for Better WordPress SEO & Security

Zobrazení obsahu pouze přihlášeným uživatelům

Do souboru functions.php (Vzhled > Upravit soubory) stačí přidat následující:


add_shortcode( 'member', 'member_check_shortcode' );

function member_check_shortcode( $atts, $content = null ) {
	 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
		return $content;
	return '';
}

Pak už stačí kdekoli v příspěvku „obalit“ text určený pouze registrovaným uživatelům tagem [member]:


[member]
Toto se zobrazí pouze přihlášeným uživatelům
[/member]

Je-li potřeba to nastavit už v šabloně vzhledu, je třeba použít


<?php
if (is_user_logged_in()):
echo "Toto se zobrazí pouze přihlášeným uživatelům";
endif;
?>

Více příkladů »

SQL dotazy k nezaplacení

Náhrada jednoho řetězce za druhý v libovolné tabulce a poli


UPDATE table_name
SET field_name = replace( field_name, 'tohle_najdi', 'timhle_nahrad' );

k nezaplacení např. při přesunu webu na jinou adresu, lze tak nahradit absolutní URL obrázků, siteurl-homeurl nebo guide


UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://stara.cz', 'http://nova.cz');
UPDATE wp_posts SET guid = REPLACE(guid, 'http://stara.cz', 'http://nova.cz');
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://stara.cz', 'http://nova.cz');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://stara.cz', 'http://nova.cz');

Tento způsob ale bohužel neřeší případ tzv. serializovaných dat Při migraci WP na jiné url je proto jistější použít nějaký specializovaný nástroj pro náhradu v serializovaných datech, např.:

http://pixelentity.com/wordpress-search-replace-domain/

https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

nebo pluginy WP Migrate DB či Better Search Replace

WP Migrate DB migrates your database by running find & replace on URLs and file paths, handling serialized data, and saving an SQL file.

Někdy je potřeba jen přidat text na konec obsahového pole


UPDATE wp_posts SET post_content =
concat(post_content, ' ...') WHERE post_type = 'post';

nebo hromadně nahradit url uvedené komentátorem


UPDATE wp_comments
SET comment_author_url =
REPLACE( comment_author_url, 'http://www.stara.cz', 'http://www.nova.cz');

Změna hesla


UPDATE 'wp_users'
SET 'user_pass' = MD5('PASSWORD') WHERE 'user_login' ='admin' LIMIT 1;

Přesun příspěvků z jednoho autora na jiného


UPDATE wp_posts
SET post_author=NEW_AUTHOR_ID
WHERE post_author=OLD_AUTHOR_ID;

Vymazání revizí a souvisejících metainformací


DELETE a,b,c FROM wp_posts a
WHERE a.post_type = 'revision'
LEFT JOIN wp_term_relationships b
ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);

Dávkové vymazání komentářů označených jako spam


DELETE from wp_comments WHERE comment_approved = '0';

Nalezení nevyužitých tagů


SELECT * From wp_terms wt
INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id
WHERE wtt.taxonomy='post_tag' AND wtt.count=0;

Výpis e-mailů vašich komentátorů


SELECT DISTINCT comment_author_email
FROM wp_comments;

Vymazání všech tagů u příspěvků najednou


DELETE a,b,c
FROM
database.prefix_terms AS a
LEFT JOIN database.prefix_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN database.prefix_term_relationships AS b
ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE (c.taxonomy = 'post_tag' AND c.count = 0);

Výpis všech nepotřebných *post meta* záznamů


SELECT * FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL;

Hromadné vypnutí komentářů u starších příspěvků


UPDATE wp_posts SET comment_status = 'closed'
WHERE post_date &lt; '2009-01-01' AND post_status = 'publish';

Deaktivace všech pluginů


UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';

Zdroj:

http://www.catswhocode.com/blog/wordpress-10-life-saving-sql-queries

http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

Automatické publikování na / z Twitteru

Twitter Tools
http://wordpress.org/extend/plugins/twitter-tools/
http://www.sutlej.net/downloads/best-related-posts/

Integrates your blog and your Twitter account so you can post links to your latest posts on Twitter, post your most recent tweets on your blog sidebar, or turn your tweets into blog posts without extra effort.

First thing you need to do is download and activate this plugin. Once you have done that follow the steps below:

1. Create a Category where you would like to post all your automated posts. You can name this category Daily Digest, Twitter, or anything you like.
2. Go to the settings of Twitter Tools Plugin in your WP-Admin.
3. Enter Your Twitter Username and Password.
4. Enable the option to post when you tweet. If you do not want to create an individual post for each tweet, your solution is the next option.
5. Enable the option to create daily digest with all your tweets from that day and modify other settings such as title of that post and title. (You can also set this to weekly digests)
6. Select the category that you made in step 1, to post your tweets.

Once you have done the above steps, you have completed the setup and its ready to go.

Display Tweets in the Sidebar

But this plugin has a lot more features then just this. You can also display your recent tweets in the sidebar using this plugin. All you have to do is either use the dynamic widget or paste the following code in your sidebar.php or any other place that you want it displayed:


<?php aktt_sidebar_tweets(); ?>

If you just want to show your last tweet then use this code:


<?php aktt_latest_tweet(); ?>

Zdroj: How to Auto Publish Your Twitter Tweets as WordPress Posts

Jak použít ve WordPressu Twitter API bez pluginu
http://www.problogdesign.com/wordpress/how-to-use-the-twitter-api-in-wordpress/

Zobrazení souvisejících příspěvků

This is a great little feature to have in your theme that saves the theme user using yet another plugin! It displays related posts based on tags, simply disappearing if there are no tags.


<?php if( function_exists('the_tags') )
// for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo '<h2>Related Posts</h2> ';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<ul> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li></ul>
<?php endwhile; }}?>

Zdroj: 10 tricks to make your WordPress theme stand out

YARP – plugin pro zobrazení souvisejících příspěvků
http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/

umožňuje:
– nastavení množiny článků, ze kterých se budou podobné články vybírat
– nastavení kritérií, podle kterých se budou vybírat podobné články
– nastavení způsobu zobrazení podobných článků na webu
– nastavení způsobu zobrazení podobných článků v RSS kanálu
– určit váhu jednotlivých hodnotících kritérií (titulek stránky, text stránky, přiřazené štítky, umístění v kategoriích

Více: http://www.portiscio.net/jak-zobrazit-podobne-clanky-ve-wordpressu

*Alternativy:*

Contextual Related Posts
https://wordpress.org/plugins/contextual-related-posts/

A powerful plugin for WordPress that allows you to display a list of related posts on your website and in your feed. The list is based on the content of the title and/or content of the posts which makes them more relevant and more likely to be of interest to your readers. This allows you to retain visitors, reduce bounce rates and refresh old entries. Contextual Related Posts is one of the most feature rich related posts plugins for WordPress with support for thumbnails, shortcodes, widgets, custom post types, caching and CSS styles.

The plugin also comes with it’s very own inbuilt stylesheet that let’s your related posts look awesome!

7 Awesome Related Post (Thumbnail) Plugins for WordPress »

Publikování příspěvků e-mailem

Postie
http://wordpress.org/extend/plugins/postie/
http://blog.robfelty.com/plugins/postie/
fórum k pluginu

Postie offers many advanced features for posting to your blog via e-mail, including the ability to assign categories by name, tag, include pictures and videos, and automatically strip off signatures.

Category and tag handling

* If you put a category name or ID in the subject with a : (or in [] or between – -) it will be used as the category for the post
* If you put the first part of a category name it will be posted in the first category that the system finds that matches – so if you put:


Subject: Gen: New News

the system will post that in General.

Using [] or — you can also post to multiple categories at once:


Subject: [1] [Mo] [Br] bla bla bla

or


Subject: -1- -Mo- -Br- bla bla bla

would post to General (Id 1), Moblog, and Brewing all at one time.

* You can add tags by adding a line in the body of the message like:


tags: foo, bar

or you can set a default tag to be applied if no tags are included.

Post to your blog using email (obecná informace z WP Codex).

Používání sessions

WordPress standardně nepodporuje sessions, což může být velmi potřebné např. při vytváření pluginu.

Stačí do functions.php (Vzhled > Upravit soubory) přidat:


if (!session_id())
add_action('init', 'session_start');

*Alternativa*

Na začátek souboru wp-config.php (hned za úvodní if (!session_id()) session_start();

Zdroj »

Jak modifikovat vzhled a délku anotace

Zdroj: Improving WordPress’ the_excerpt() template tag

WordPress’ the_excerpt() template tag is used in most themes for browsing the archives and categories of a blog. Rather than displaying the full content of the post, the excerpt displays a short snippet of the content. Unless you manually enter in an excerpt when writing each post, WordPress grabs the first 55 words of the post and uses that as the excerpt.

So far so good, but there are problems with the way WordPress does this. These include:

* Word count – 55 words is a good number, but what if you want more or less?
* Formatting – WordPress strips out all HTML tags. This gets rid of images and links, but can also get rid of paragraph formatting, making the entire excerpt one long paragraph without any line breaks.
* JavaScript – Unfortunately JavaScript isn’t stripped out, which can result in some plugins’ messy script appearing in your excepts. Not only does this look rubbish, it can be a vulnerability too.

Stačí z wp-includes/formatting.php zkopírovat funkci wp_trim_excerpt, přejmenovat ji třeba na better_excerpt a vložit ji do functions.php (Vzhled > Upravit soubory)


function better_excerpt($text) {
	global $post;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content', $text);
		$text = str_replace(']]>', ']]&gt;', $text);
		$text = strip_tags($text); // můžu zakázat
		$excerpt_length = 55; // můžu změnit délku
		$words = explode(' ', $text, $excerpt_length + 1);
		if (count($words)> $excerpt_length) {
			array_pop($words);
			array_push($words, '[...]');
			$text = implode(' ', $words);
		}
	}
	return $text;
}

Na závěr je nutno na konec functions.php vložit ještě následující 2 řádky, které způsobí, že WP místo vestavěné funkce wp_trim_excerpt použije naši vylepšenou better_excerpt.


remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'better_excerpt');

Implementováno na tomto webu.

Customizing the Read More
http://codex.wordpress.org/Customizing_the_Read_More

změna textu odkazu:


<!-- more Tady tenhle článek pokračuje -->

Useful ways to customize and format the WordPress more tag »

Advanced Excerpt Plugin
http://wordpress.org/extend/plugins/advanced-excerpt/

This plugin adds several improvements to WordPress‘ default way of creating excerpts.

– Keeps HTML markup in the excerpt (and you get to choose which tags are included)
– Trims the excerpt to a given length using either character count or word count
– Only the ‚real‘ text is counted (HTML is ignored but kept)
– Customizes the excerpt length and the ellipsis character that are used
– Completes the last word or sentence in an excerpt (no weird cuts)
– Adds a read-more link to the text
– Ignores custom excerpts and use the generated one instead
– Theme developers can use the_advanced_excerpt() for even more control (see the FAQ

Jak nakopnout WordPress správným směrem

Tento návod je určen spíše pro začátečníky, kteří si právě nainstalovali WordPress. Je pravděpodobné, že pokročilí uživatelé budou znát většinu informací, které zde uvádím. Nicméně i těm doporučuji přečíst si článek – už jenom kvůli ověření a osvěžení nabytých vědomostí.
Čistě nainstalovaný redakční systém WordPress je prázdný, postrádá celou řadu funkcí a potřebuje změnit […]