WordPress Code Snippets

WordPress customizable code snippets provide you with mini-solutions for the plugin, theme or an add-on you’re building, or for enhancing the behavior of your existing website.

To apply the snippet:

  • Run WP Master Developer, type in the first few letters of a snippet and press CTRL + SPACE. This brings up the list of all available templates.
  • Select the template, fill out the form (if there is one) to customize it, and the program generates all the source code for you.

Comments

Snippet: wp_comments_remove_autolinking     Video: watch     File to modify: functions.php
What does it do: stops the auto-conversion of links in comments
Why: to prevent the spammers from siphoning off the traffic from your website

Snippet wp_comments_remove_url_field:     Video: watch     File to modify: functions.php
What does it do: completely removes the URL filed in the comments
Why: because it is too often abused by spammers, who make useless comments just to be able to publish their URL

Snippet: wp_comments_set_min_length     Video: watch     File to modify: functions.php
What does it do: specifies the minimal number of characters a comment must have
Why: because spammers often make useless short comments such as "Thank you for the great post" so that they could publish their URL

Editing

Snippet: wp_quicktag     Video: N/A     
What does it do: lets you include an additional button in the Text (HTML) mode of the WordPress editor.
Why: to enhance the editing capabilities

Snippet: wp_quicktags     Video: N/A     
What does it do: lets you create the additional set of buttons in the Text (HTML) mode of the WordPress editor.
Why: to enhance the editing capabilities

Database

Snippet: wp_db_autorepair     Video: watch     File to modify: wp-config.php
What does it do: enables automatic WordPress database repair and optimization
Why: over time, the automatic WordPress database becomes less effective and may develop errors

Plugins

Snippet: wp_plugin     Video: N/A     File to modify: [your plugin].php
What does it do: defines a new plugin

Posts and Pages

Snippet: wp_disable_post_revisions     Video: watch     File to modify: wp-config.php
What does it do: completely disables the saving of post/page revisions.
Why: being able to restore an old page/post revision is useful, but it also takes up huge amounts of space, making the database less efficient. If you are happy to work with the latest version of your post/page, you can disable the saving of revisions.

Snippet: wp_limit_post_revisions     Video: watch     File to modify: wp-config.php
What does it do: lets you specify how many latest page/post revisions do you want to keep
Why: if you do not want to completely disable post revisions, you can limit their number to keep the database smaller and more efficient.

Snippet: wp_search_exclude_pages     Video: watch     File to modify: functions.php
What does it do: excludes pages from the search results. The search returns only the posts.
Why: if your site only has pages such as Privacy Policy, Acceptable Use, and the like, it makes sense to only show the posts and exclude the pages from the search results.

Security

Snippet: wp_hide_version     Video: watch     File to modify: functions.php
What does it do: hides the WordPress version.
Why: knowing the version of the WordPress you’re running makes it easier for hackers to attack you.

Shortcodes

Snippet: wp_shortcode     Video: N/A     
What does it do: adds the shortcode and creates the function for it.
Why: to enhance the editing of posts and pages.

Snippet: wp_shortcode_enclosing     Video: N/A     
What does it do: adds the shortcode and creates the function for it. The shortcode opening and closing tags enclose the content.
Why: to enhance the editing of posts and pages.

Snippet: wp_shortcode_with_attributes     Video: N/A     
What does it do: adds the shortcode and creates the function for it. The shortcode accepts the set of attributes.
Why: to enhance the editing of posts and pages.

Snippet: wp_shortcodes_register     Video: N/A     
What does it do: adds the action and the function to register all the shortcodes.

Snippet: wp_year     Video: watch     File to modify: functions.php
What does it do: creates the [year] shortcode to display the current year in posts and pages.
Why: useful if you need to update the copyright and other information to show the current year. This does it automatically.

System

Snippet: wp_disable_autoupdates     Video: watch     File to modify: wp-config.php
What does it do: completely disables WordPress auto-updating
Why: a plugin or a theme may break down after a WordPress update. This allows you to test things first before updating.

Snippet: wp_empty_trash     Video: watch     File to modify: wp-config.php
What does it do: lets you specify the number of days to keep the posts and pages in the trash before the auto-emptying.
Why: keeping the posts and pages in the trash for shorter periods keeps the database smaller and more efficient.

Snippet: wp_redirect_after_registration    Video: watch     File to modify: functions.php
What does it do: redirects the user to the specified page after registering

Snippet: wp_set_autoupdates     Video: watch     File to modify: wp-config.php
What does it do: lets you choose the way WordPress auto-update works. You can enable minor updates only, all updates including major and minor, or disable auto-updating altogether.
Why: to fine-tune the auto-updating.

Widgets

Snippet: wp_widgets_enable_shortcodes     Video: watch     File to modify: functions.php
What does it do: makes it possible to use shortcodes in your widgets.
Why: to greatly enhance the widget functionality.