WordPress
WordPress |
---|
CDN · CSS · Hardening |
Plugins |
BreezingForms |
WooCommerce |
- 7 PayPal Alternatives for Freelancers to Collect Payments in WordPress
- 10 Quick Ways to Clean Up and Optimize Your WordPress Site
- WordPress theme Twenty Twenty-One: Modifications and customizations of headers, fonts, styles and more
- Fast & Easy WordPress Mega Menu without Plugins
Add javascript to functions.php file
The code below will add the javascript in the file showhide.js to just the page 21398.
/**
* Enqueue show/hide script for Painting page (2019 draft)
*/
function load_showhide_assets() {
if( is_page( 21398 ) ) {
wp_enqueue_script('showhide', get_stylesheet_directory_uri() . '/js/showhide.js', array('jquery'), '', false);
}
}
Add jQuery
Add whitespace
<br class="blank" />
Block theme support
Change default From: address
Simply paste the following snippet into your functions.php file. Don't forget to put the desired email address on line 5 and desired name on line 8.
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
function new_mail_from($old) {
return '[email protected]';
}
function new_mail_from_name($old) {
return 'Your Blog Name';
}
Or, if you want WordPress to grab the email address from what you have set as the Administrator email address and use the name of your blog, use this code instead:
function res_fromemail($email) {
$wpfrom = get_option('admin_email');
return $wpfrom;
}
function res_fromname($email){
$wpfrom = get_option('blogname');
return $wpfrom;
}
add_filter('wp_mail_from', 'res_fromemail');
add_filter('wp_mail_from_name', 'res_fromname');
CSS target page example
/* Change text color on Videos page for video titles */
.page-id-4414 .module_row_0.module_row a {
color: white !important;
}
Customize RSS feed
Filter
Add to functions.php:
/* RSS filter, show only items in Category Blog */
function feedFilter($query) {
if ($query->is_feed) {
$query->set('category_name', 'blog');
}
return $query;
}
add_filter('pre_get_posts','feedFilter');
'Float' heading
To allow images to wrap around headings, you need to create a CSS class:
/* Add class "float" to h2 to float image around h2 */
#content h2.float {
clear: none;
}
Then just use the class:
<h2 class="float">Assembly Only</h2>
Force new paragraph after floating image
Add the following above the text you don't want to float around the image:
<p style="clear:both;"></p>
Force SSL for logged in users
From this link: Force logged in wordpress users to HTTPS.
Add this block of code to the top of the themes header.php file within php tags:
// This forces logged in users to use HTTPS
if (is_user_logged_in() && ($_SERVER['SERVER_PORT'] !== '443')){
wp_redirect("https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
}
Optionally, you can use the plugin:
Increase the WordPress RSS Widget Refresh Rate
One of the most common complaints on the WordPress support forum is that the content of the RSS widget doesn't update, or doesn't update frequently enough.
Here's the scoop, each widget instance checks the feed once every 12 hours. Twice a day — that's it. And that ain't much.
You can change this setting by adding the following to your current theme's function.php:
add_filter( 'wp_feed_cache_transient_lifetime', create_function('$a', 'return 1800;') );
The above code will cause the feeds to be checked every 30 minutes.
1800 = 1800 seconds == 30 minutes.
Increase memory allocated
Add (or change) the following in the wp-config.php file:
define('WP_MEMORY_LIMIT', '192M');
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
- This is for the administration dashboard. If editing seems slow, raising this limit can help.
Note that this is setting the php memory allocated to WordPress. The maximum php memory available depends upon your hosting.
Migrating WordPress to another server
There is plenty of advice on moving your WordPress site. Not much on how to deal with it without having planned it first. But what if you want to install another copy of your current site from a backup for testing or other purposes? Without having to create a special backup just for this?
- Migrating WordPress Across Hosts, Servers and URLs
- Migrating a WordPress/WPMU/BuddyPress Website
- Search Replace DB
Multiple themes
- Multiple Themes plugin - Also known as jonradio Multiple Themes.
Recommended plugins
- See also: Security: Plugins
- Blogger Importer - The Blogger Importer imports your blog data from a Google Blogger site into a WordPress.org installation.
- Coming Soon Page & Maintenance Mode by SeedProd
- Custom Meta Widget
- Gwolle Guestbook
- Include HTML and PHP
- MaxButtons - WordPress Button Plugin MaxButtons. A CSS3 button generator for WordPress that's powerful and so easy to use that anyone can create beautiful buttons.
- Online Backup for WordPress
- Peter's Login Redirect
- Postman SMTP Mailer/Email Log - Send, log and troubleshoot your Outgoing Email easily.
- Preserved HTML Editor Markup Plus - This plugin preserves the user-generated HTML markup in the TinyMCE editor.
- Remove Dashboard Access - No longer recommended. Use WP Hide Dashboard (below) instead.
- Table of Contents Plus
- TablePress
- Tab Slide
- TinyMCE Advanced - This plugin will let you add, remove and arrange the buttons that are shown on the Visual Editor toolbar. In addition, you can use it to prevent the Visual Editor from removing <p> and <br /> tags.
- UpdraftPlus - WordPress Backup Plugin. Not tested but highly recommended by others.
- User Specific Content
- WooCommerce Cart Tab - This will display a link to the WooCommerce cart which is visible sitewide and fixed in position so it remains visible wherever the user scrolls.
- WordPress HTTPS (SSL)
- WordPress Mobile Pack
- WP Custom Menu Filter Plugin
- WP Hide Dashboard
- Yoast SEO
Cache / Optimization
- Optimize Database after Deleting Revisions - Optimizes the WordPress Database after Cleaning it out. Deletes redundant revisions of posts and pages.
- WP Fastest Cache - Caches and optimizes (minify / combine / compress). Undergoing testing now to replace WP Super Cache.
- WP Super Cache
Embed
- Effortless Google Maps
- Google Doc Embedder - Lets you embed PDF, MS Office, and many other file types in a web page using the free Google Docs Viewer (no Flash or PDF browser plug-ins required). If you are able to store your files in Google Drive, try the Google Drive Embedder plugin. This will be faster to display, and more reliable.
- Inline Google Spreadsheet Viewer - Highly recommended.
Forms
Top recommendation
- Caldera Forms - Create beautiful, responsive forms with a simple drag and drop editor.
Other plugins
- BreezingForms - No longer recommended, use Caldera Forms.
- Fast Secure Contact Form
- Formidable - No longer recommended, use Caldera Forms.
- Jazzy Forms - Online form builder, ideal for cost-estimates and calculations.
Media
- Find Posts Using Attachment - Allows to find all posts where a particular attachment (image, video, etc.) is used. Not yet tested here.
- Image Cleanup - Image Cleanup will index unreferenced images. Not yet tested here.
- Media Cleaner - Clean your Media Library from the media which aren’t used in any of your posts, gallery and so on. Not yet tested here.
- Simple Lightbox - Simple Lightbox is a very simple and customizable lightbox that is easy to add to your WordPress website.
- Soundy Audio Playlist
- WP Smush - Reduce image file sizes, improve performance and boost your SEO using the free WPMU DEV WordPress Smush API.
Social media
Conflicts
As of November 16, 2017, having the Yoast SEO plugin active causes the Description text windows in BreezingForms to show as empty when you attempt to edit them. The workaround is to disable the Yoast SEO plugin while working on that part of a form.
Remove page title
You’ll want to go to your theme’s stylesheet. (Appearance > Editor > Stylesheet – style.css)
At the bottom of the stylesheet, use the following CSS example for Pages:
.page-id-1826 .entry-title {display: none;}
Be sure to change the page ID to match the one of the page.
Remove title of the blog
Add
#header h1 { display:none }
at the end of style.css and save it.
Responsive site logo
/* Makes site logo responsive, it will be across the whole top of the screen regardless of screen size */
#site-logo {
max-width: 100%
}
Security
Advice
Plugins
Stop WordPress creating paragraphs automatically
Add the following to your functions.php file:
remove_filter( 'the_content', 'wpautop' );
remove_filter('the_excerpt', 'wpautop');
Trash
Items marked as Trash will be placed in the Trash container for each item (All, Published, Trash). WordPress will automatically remove all Trash items after they have been there for 30 days.
If you would like to prevent the automatic removal, there are several methods. The easiest is to add the following to your wp-config.php file:
/** Change time to empty Trash to 32000 days (88 years) */
define('EMPTY_TRASH_DAYS', 32000);
Go to URL upon Formidable Form submission
/* Go to Payment page after submit on Join Jacksonville Jazz Society application form */
add_action('frm_after_create_entry', 'go_to_payment', 25 );
function go_to_payment($entry_id){
global $frm_entry;
$entry = $frm_entry->getOne($entry_id);
if ($entry->form_id == FORM ID GOES HERE){
die("<script type='text/javascript'>window.location='http://urltogoto.com/' </script>");
}
}
#menu-icon:before {
content: "Menu";
font-family: inherit;
}
Tabby Tabs workaround
For the plugin Tabby Responsive Tabs, using a single non-alphanumeric title can cause an issue.
The workaround would be to add some hidden text to the titles.
eg:
[tabby title="£<i>GBP</i>"]
[tabby title="€<i>EUR</i>"]
[tabby title="$<i>USD</i>"]
Then add some CSS in the customizer’s custom CSS to hide these added i elements:
.responsive-tabs .responsive-tabs__list__item i,
.responsive-tabs .responsive-tabs__heading i {
display: none;
}
Warning: Cannot modify header information
Warning: Cannot modify header information – headers already sent by
You receive an error message on your browser "Warning: Cannot modify header information – headers already sent by (output started at /path/blog/wp-config.php:34)" right after upgrading your WordPress. This error occurs when there happen to be unrequired spaces in a given file, in this example it's the wp-config.php. To fix the issue, you should edit and remove the undesired white space from that file:
- Access via FTP and download the file mentioned in the error message
- Open it with a text editor
- Remove all spaces before the tag
- Upload the edited file back via FTP
This error could involve other files too. So it's pretty important to read the error message carefully as it states the specific file name (and path) where the error occurred.
Add External Link to Featured Image
Place this in your custom functions.php file.
// Add External Link to Featured Image with Custom Field
add_filter('post_thumbnail_html','add_external_link_on_page_post_thumbnail',10);
function add_external_link_on_page_post_thumbnail( $html ) {
if( is_singular() ) {
global $post;
$name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) {
$html = '<a href="' . ( $name ) . '" target="_blank" >'. $html . '</a>';
}
}
return $html;
}
$html = '<a href="' . ( $name ) . '" target="_blank" >' . $html . '</a>';