WordPress

From IT Wiki
Jump to: navigation, search
See also: CSS > WordPress

Add custom functions.php and/or style.css

Normally, when you want to add these files for customization, you create a child theme. However, some frameworks have the theme you use be a child theme and you can't make a "grandchild" theme in WordPress.

So in order to keep your custom changes separate from the child theme you can do the following:

First, create empty "myfunctions.php" and "mycustom.css" files (you can name them what you wish, just make sure the extensions are .php and .css, respectively, and change the names in the code below to match) in the child theme's folder.
Put <?php as the first line of the myfunctions.php file.
Next, in the child theme's functions.php file add the following (it is recommended you place this at the bottom of the file):
/* Add custom style sheet */
function custom_style_sheet() {
wp_enqueue_style( 'custom-styling', get_stylesheet_directory_uri() . '/mycustom.css' );
}
add_action('wp_enqueue_scripts', 'custom_style_sheet');

/* Call secondary functions.php file */
require_once("myfunctions.php");

Add whitespace

<br class="blank" />

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.

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?

Recommended plugins

See also: Security: Plugins

Cache / Optimization

Embed

Forms

Top recommendation

  • Caldera Forms - Create beautiful, responsive forms with a simple drag and drop editor.

Other plugins

Media

  • 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.

/* 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

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>");
}
}

Change hamburger menu icon

#menu-icon:before {
    content: "Menu";
    font-family: inherit;
}