26 February 2024

29 WordPress Tweaks to Make Your Posts and Pages Pop

By Ronald Smith

WordPress is an amazing website builder, but sometimes its default settings don’t quite match what you’re looking for, especially when it comes to how your posts are displayed. That’s where personalization steps in. If you want to create a unique brand and leave a lasting impression on your visitors, you need to customize your website. Luckily, bloggers and developers have been hard at work to find clever ways to make your posts stand out.

In this article, I’ll show you a bunch of cool tweaks you can make to your WordPress posts. These changes will not only enhance the user experience but also boost your revenue and increase page views. And the best part? Most of these tweaks don’t require any fancy plugins. They’re super easy to implement – just copy and paste the code we provide, and you’re good to go!

Hey there! Whether you’re working on something for yourself or for work, these little changes will help you make your site even better. Let’s jump right in and customize your WordPress experience!

Changes for the Front-End of WordPress

1. Adjust Your Excerpt Length

With this tweak, you can change how long your excerpts are. Just copy and paste the following code into your functions.php file, and set the value as 75 to determine the length of your excerpts.

add_filter(‘excerpt_length’, ‘my_excerpt_length’); function my_excerpt_length($len)

2. Show Dates in a “Time Ago” Format like Twitter

Did you know that WordPress can show dates in a special “Time Ago” format? You can use the code snippet below anywhere in your loop to display the date in that format.

<?php echo “function custom_post_thumbnail_in_rss_feed( $content ) {“;

echo “if( has_post_thumbnail( get_the_ID() ) ) {“;

echo “$thumbnail = get_the_post_thumbnail( get_the_ID(), ‘thumbnail’ );”;

echo “$content = $thumbnail . $content;”;

echo “}”;

echo “return $content;”;

echo “}”;

echo “add_filter( ‘the_excerpt_rss’, ‘custom_post_thumbnail_in_rss_feed’ );”;

echo “add_filter( ‘the_content_feed’, ‘custom_post_thumbnail_in_rss_feed’ );”;

echo “?>”

In my WordPress themes, I can enhance the appearance of my post feeds by displaying thumbnails alongside the content. To implement this, I use a handy function called diw_post_thumbnail_feeds. It works by including the post thumbnail within the respective feed content. This feature is especially useful for making my posts more visually appealing and engaging for readers who browse through my website feeds.

Now, let’s move on to restricting search results to post titles only. This is a great way to refine the search functionality and make it more focused. To achieve this, I can add a small code snippet to my functions.php file within my WordPress theme. This snippet ensures that when users search for content on my website, the search algorithm only considers the titles of the posts. By filtering out other parts of the content, such as the body text, the search results become more precise and relevant to what users are looking for.

By employing these techniques, I can enhance both the visual appeal and usability of my WordPress website.

Have you ever wondered how to search for something on a website? I’m here to tell you all about it! When you enter a search term into a website’s search bar, the site uses a special function to find what you’re looking for. Let’s take a closer look at how this works.

First, the website checks if you actually entered anything in the search bar. If you didn’t, there’s no need to process anything further. The website then looks at the search terms you entered and prepares them for searching.

Next, the website starts searching for the terms you entered, specifically in the titles of the website’s posts or articles. It uses a clever trick to match the search terms with the post titles, making sure it finds the right information.

But what if you entered more than one search term? The website takes care of that too! It knows that you might be looking for multiple things at once. It checks if the search terms you entered are all in the same sentence or if they are separate concepts. This way, it can provide more accurate search results.

Once the website has finished searching, it adds up all the results and presents them to you. It also takes into account any additional conditions, like if you need to be logged in to see certain posts or if some posts require a password.

And that’s it! Now you know how websites search for information based on what you enter in the search bar. It’s a clever process that helps you find what you’re looking for quickly and easily. So go ahead and start searching for the things you love!

5. Show an Increasing Number on Every Post

Here’s a cool trick you can use to display a number that increases with each post. It’s really easy to do. First, copy and paste the following code into your functions.php file:

function updateNumbers() {

global $wpdb;

$querystr = “SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = ‘publish’ AND $wpdb->posts.post_type = ‘post'”;

$pageposts = $wpdb->get_results($querystr, OBJECT);

$counts = 0;

if ($pageposts):

foreach ($pageposts as $post):

setup_postdata($post);

$counts++;

add_post_meta($post->ID, ‘incr_number’, $counts, true);

update_post_meta($post->ID, ‘incr_number’, $counts);

endforeach;

endif;

}

add_action(‘publish_post’, ‘updateNumbers’);

add_action(‘deleted_post’, ‘updateNumbers’);

add_action(‘edit_post’, ‘updateNumbers’);

Now, every time you publish, delete, or edit a post, the number displayed on each post will automatically increase. How cool is that? Give it a try and see the numbers go up with each new post you create!

When you finish, you can use the following code to show the post number. Remember, you have to use it inside the loop.

<?php echo get_post_meta($post->ID, ‘incr_number’, true); ?>

6. Hide a Post from the WordPress Feed

Do you want to hide specific posts from your feed? Here’s a trick for you. Just remember to apply the filter in the right place. In our example, we’re filtering within the feed $wp_query->is_feed. If you don’t set it up correctly, the filter could also affect your backend and those posts won’t be visible in the post overview.

The function requires two parameters. First, you provide an extension of the SQL string to the $where parameter, which takes care of the filtering based on the ID. Then, inside the brackets, you need to insert the IDs of the posts you want to filter.

Here’s a revised version of the provided text, maintaining the same meaning but in a simpler and more engaging style:

“`php

function fb_post_exclude($where, $wp_query = NULL) {

global $wpdb;

if (!$wp_query) {

global $wp_query;

}

if ($wp_query->is_feed) {

// Exclude posts with ID 40 and 9

$where .= ” AND $wpdb->posts.ID NOT IN (40, 9)”;

}

return $where;

}

add_filter(‘posts_where’ ‘fb_post_exclude’, 1, 2);

“`

7. Find a Single Result and Redirect to the Post

Copy and paste this code snippet into your WordPress theme’s functions.php file. It automatically redirects your search to the post when there’s only one search result in WordPress.

“`php

add_action(‘template_redirect’, ‘single_result’);

function single_result() {

if (is_search()) {

global $wp_query;

if ($wp_query->post_count == 1) {

wp_redirect(get_permalink($wp_query->posts[0]->ID));

exit;

}

}

}

“`

8. Create Meta Descriptions from the Content

Use this code snippet in your WordPress theme’s functions.php file to automatically generate meta descriptions from your post’s content.

If you want to automatically create a meta description for your WordPress post and remove all shortcodes and tags, you can add this code snippet to your theme’s functions.php file. Don’t forget to include it in the header.php file as well, or it won’t work properly.

“`php

function create_meta_desc() {

global $post;

if (!is_single()) {

return;

}

$meta = strip_tags($post->post_content);

$meta = strip_shortcodes($post->post_content);

$meta = str_replace(array(“

“, “

“, “\t”), ‘ ‘, $meta);

$meta = substr($meta, 0, 125);

echo “”;

}

add_action(‘wp_head’, ‘create_meta_desc’);

“`

Now, let’s move on to another helpful code snippet that can automatically replace words with affiliate links.

Wouldn’t it be great if you could automatically replace certain words in your WordPress posts with affiliate links? Well, you’re in luck! The code snippet below will allow you to do just that.

“`php

function replace_words_with_links($content) {

$words_to_replace = array(

‘word1’ => ‘https://affiliate-link1.com’,

‘word2’ => ‘https://affiliate-link2.com’,

‘word3’ => ‘https://affiliate-link3.com’

);

foreach ($words_to_replace as $word => $link) {

$content = str_ireplace($word, “$word“, $content);

}

return $content;

}

add_filter(‘the_content’, ‘replace_words_with_links’);

“`

Simply add this code to your theme’s functions.php file, and the specified words in your posts will be automatically replaced with the corresponding affiliate links. This can be a huge time-saver, as you won’t have to manually add affiliate links every time you mention a certain word.

Feel free to modify the code snippet to fit your specific needs. You can add or remove words and links as necessary.

I hope you find these code snippets helpful and that they enhance your WordPress experience. Enjoy!

If you want to automatically replace words with affiliate links, follow these steps:

1. Open your functions.php file.

2. Copy and paste the code below into the file:

function replace_text_wps($text) {

$replace = array(

‘WORD TO REPLACE’ => ‘REPLACE WORD WITH THIS’,

‘thesis’ => ‘<a href=”http://mysite.com/myafflink”>thesis</a>’,

‘studiopress’ => ‘<a href=”http://mysite.com/myafflink”>studiopress</a>’

);

$text = str_replace(array_keys($replace), $replace, $text);

return $text;

}

add_filter(‘the_content’, ‘replace_text_wps’);

add_filter(‘the_excerpt’, ‘replace_text_wps’);

3. Replace ‘WORD TO REPLACE’ with the word you want to replace, and ‘REPLACE WORD WITH THIS’ with the word you want to replace it with. For example, if you want to replace the word “thesis” with a link, you would enter: ‘thesis’ => ‘<a href=”http://mysite.com/myafflink”>thesis</a>’.

4. Save the changes to your functions.php file.

By following these instructions, you will be able to automatically replace specific words with affiliate links on your website. Take advantage of this feature to improve the functionality and monetization of your content.

If you want to add a “read more” link to the end of the excerpt in your WordPress theme, you can do it by adding the following code to the functions.php file:

function excerpt_readmore($more) {

return ‘… ‘ . ‘Read More‘;

}

add_filter(‘excerpt_more’, ‘excerpt_readmore’);

11. Display Related Posts Without Using a Plugin

To display related posts on your WordPress site based on the current post’s tags, you can use the code below. Simply add it to your single.php file, or any other location where you want to show the related posts:

Hey there! Today I want to show you how to create a popular posts sidebar for your website. Having a sidebar that features your most popular posts is a great way to engage your readers and keep them on your site for longer. It’s also a fantastic opportunity to showcase your best content. So let’s get started!

First, we’ll need to gather some information about our popular posts. We can do this by looking at the tags assigned to each post. So let’s add some code to retrieve the tags associated with our current post:

<?php $tags = wp_get_post_tags($post->ID); ?>

Next, we’ll create an array to store the IDs of these tags:

<?php $tag_ids = array(); ?>

Now, we’ll loop through each tag and add its ID to our array:

<?php foreach ($tags as $individual_tag) { ?>

<?php $tag_ids[] = $individual_tag->term_id; ?>

<?php } ?>

Great! Now that we have our tag IDs, we can use them to find related posts. We’ll set up some arguments for our query, including the tag IDs, the current post ID, the number of related posts to show, and a flag to prevent the current post from being included in the results:

<?php

$args = array(

‘tag__in’ => $tag_ids,

‘post__not_in’ => array($post->ID),

‘showposts’ => 5,

‘caller_get_posts’ => 1

);

?>

Now it’s time to run our query and display the related posts. We’ll use a while loop to go through each post and show its title and permalink:

<?php

$my_query = new wp_query($args);

if ($my_query->have_posts()) {

echo ‘<h3>Related Posts</h3><ul>’;

while ($my_query->have_posts()) {

$my_query->the_post();

?>

<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>

<?php

}

echo ‘</ul>’;

}

?>

And there you have it! With just a few lines of code, we’ve created a popular posts sidebar that showcases related posts based on their tags. Feel free to customize the number of related posts shown or the styling of the sidebar to fit your website’s design.

I hope you found this tutorial helpful. Enjoy creating your own popular posts sidebar!

Setting up a sidebar widget to display popular posts is really simple. All you have to do is copy and paste this code into your sidebar.php file. And if you want to change the number of posts shown, just change the “5” at the end of line 3 to whatever number you want.

Here’s the code:

Popular Posts

    $result = $wpdb->get_results(“SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0, 5”);

    foreach ($result as $post) {

    setup_postdata($post);

    $postid = $post->ID;

    $title = $post->post_title;

    $commentcount = $post->comment_count;

    if ($commentcount != 0) {

    ?>

  • }

    }

    ?>

Now, let’s move on to something else. Here’s a handy tip on how to set an expiration date and time for your posts. Just follow these steps:

1. Open the post you want to add an expiration date/time to.

2. Scroll down to the “Publish” box on the right side of the screen.

3. Click on the “Edit” link next to “Publish immediately”.

4. A calendar will appear. Select the date and time you want the post to expire.

5. Click the “OK” button.

6. Update or publish the post.

And that’s it! Now your post will automatically expire at the specified date and time. This can be useful for events, limited-time promotions, or any other time-sensitive content you want to display on your website. Don’t forget to check the date and time settings on your server to make sure they’re accurate.

Below is a handy code snippet that you can use in your WordPress Themes to add the ability to set expiration dates and times for your posts. Just follow these steps to make it work:

1. Open your theme file and locate the WordPress loop.

2. Replace the existing loop code with the modified version below:

$expirationtime = get_post_custom_values(‘expiration’);

if (is_array($expirationtime)) {

$expirestring = implode($expirationtime);

}

$secondsbetween = strtotime($expirestring) – time();

if ($secondsbetween > 0) {

// Show the post content

the_title();

the_excerpt();

}

endwhile; endif; ?>

To set a post expiration date, follow these steps:

1. Create a custom field for the post.

2. Use “expiration” as the key.

3. Enter the desired expiration date and time in the format “mm/dd/yyyy 00:00:00” as the value.

4. After the specified timestamp, the post will no longer be visible on your website.

Lastly, if you want to list future posts, simply use the provided code above, and it will handle the display of posts based on their expiration date.

Hey there! Did you know you can make a WordPress feature that displays future posts? It’s pretty cool! Just copy and paste this code wherever you want your future posts to show up:

<div><div><p>Future events</p></div> <?php query_posts(‘showposts=10&post_status=future’); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div> <p><strong><?php the_title(); ?></strong><?php edit_post_link(‘e’,’ (‘,’)’); ?><br /> <span><?php the_time(‘j. F Y’); ?></span></p> </div> <?php endwhile; else: ?><p>No future events scheduled.</p><?php endif; ?> </div>

15. Only Show AdSense to Search Engines

Hey! I’ve got a cool trick to share with you. Did you know that you can show AdSense ads to people who come to your website from search engine results? It’s pretty easy to do. Just follow these steps:

1. Open up your theme’s “functions.php” file.

2. Copy and paste the code below into the file:

“`

function scratch99_fromasearchengine() {

$ref = $_SERVER[‘HTTP_REFERER’];

$SE = array(‘/search?’, ‘images.google.’, ‘web.info.com’, ‘search.’, ‘del.icio.us/search’, ‘soso.com’, ‘/search/’, ‘.yahoo.’);

foreach ($SE as $source) {

if (strpos($ref, $source) !== false) {

return true;

}

}

return false;

}

“`

3. Now, you can customize the code by adding any search engines you want. Just add them to the `$SE` array.

4. Finally, place the code wherever you’d like the AdSense ads to appear in your website’s template.

That’s it! By following these steps, you’ll only show AdSense ads to visitors who come to your site from search engine results. How cool is that? Give it a try and see how it boosts your ad performance!

If I were you, I would make a few adjustments to the WordPress backend. Here are some tweaks you can try out:

1. Let’s start by enabling additional HTML tags in the editor. By default, the WordPress editor only allows HTML tags that comply with the XHTML 1.0 standard. But don’t worry, I’ve got a simple solution for you. Just follow these steps:

– Open your theme’s functions.php file.

– Copy and paste the code snippet below into the file.

– Save the file, and you’re good to go!

“`php

if (function_exists(‘scratch99_fromasearchengine’)) {

if (scratch99_fromasearchengine()) {

// INSERT YOUR CODE HERE

}

}

“`

Now, you’ll be able to use more HTML tags in the WordPress editor. It gives you greater flexibility and control over your content. Enjoy exploring new possibilities!

Hey there! Let me show you a cool trick to modify the default editor in WordPress admin. You can either stick with the Visual Editor or go for the HTML Editor. Just add either of them into the functions.php file. Check it out:

“`php

function fb_change_mce_options($initArray) {

// Comma separated string of extended tags

// Comma separated string of extended elements

$ext = ‘pre[id name class style],iframe[align longdesc name width height frameborder scrolling marginheight marginwidth src]’;

if (isset($initArray[‘extended_valid_elements’]))

$initArray[‘extended_valid_elements’] .= ‘,’ . $ext;

else

$initArray[‘extended_valid_elements’] = $ext;

// maybe; set tiny parameter verify_html

//$initArray[‘verify_html’] = false;

return $initArray;

}

add_filter(‘tiny_mce_before_init’, ‘fb_change_mce_options’);

“`

By making this simple change, you can customize your editor and enhance your WordPress experience. Give it a shot!

# Setting the Default Editor in WordPress

Let’s learn how to change the default editor in WordPress using some simple code. There are two options we can explore: the Visual Editor and the HTML Editor.

## Option 1: Setting the Visual Editor as Default

To set the Visual Editor as your default, use the following code snippet in your `functions.php` file:

“`php

add_filter(‘wp_default_editor’, create_function(”, ‘return “tinymce”;’));

“`

This code will make the Visual Editor your go-to option whenever you create or edit posts.

## Option 2: Setting the HTML Editor as Default

Alternatively, if you prefer the HTML Editor, you can use this code:

“`php

add_filter(‘wp_default_editor’, create_function(”, ‘return “html”;’));

“`

This will make the HTML Editor the default choice for creating and editing posts.

Choose whichever editor you feel most comfortable with and use the corresponding code snippet to set it as your default.

## Applying Different Editor Stylesheets for Various Post Types

If you want to have different editor stylesheets for different post types, you can use the following code in your `functions.php` file. Just make sure to adapt it to your specific post types and update the stylesheet names accordingly.

“`php

// Add your code here

“`

With this code, you can customize the appearance of your editor based on the specific post type you are working on. Let your creativity flow and make each post type stand out with its own unique style!

Remember to always save your `functions.php` file after making any changes. Happy coding!

Editing Styles in WordPress

When it comes to editing styles in WordPress, there are a few things I need to keep in mind. First and foremost, I need to make sure I’m using the right editor style for each type of content I’m working on. Luckily, WordPress makes it easy for me to do this. All I have to do is add a snippet of code to my functions.php file.

Here’s a simple function I can use to assign different editor styles to different post types:

“`html

function my_editor_style() {

global $current_screen;

switch ($current_screen->post_type) {

case ‘post’:

add_editor_style(‘editor-style-post.css’);

break;

case ‘page’:

add_editor_style(‘editor-style-page.css’);

break;

case ‘portfolio’:

add_editor_style(‘editor-style-portfolio.css’);

break;

}

}

add_action(‘admin_head’, ‘my_editor_style’);

“`

By using this code, I can easily assign custom editor styles to specific post types. For example, I can have a different style for my blog posts, pages, and portfolio items. This allows me to have more control over the appearance of my content and make sure it looks consistent throughout my site.

4. Uploading Additional File Types

There may be times when I want to upload file types that WordPress doesn’t allow by default. For example, if I want to upload files with a .tmCommand extension, I won’t be able to do it using the built-in WordPress Uploader.

However, there’s a simple solution to this problem. I can use a snippet of code that allows me to upload additional file types. All I need to do is add this code to my functions.php file, and I’m good to go. And the best part is, I can even add more file types by simply separating them with a pipe (|).

“`html

// Allow upload of additional file types

function allow_upload_of_additional_file_types($mime_types) {

$mime_types[‘tmCommand’] = ‘text/plain’;

return $mime_types;

}

add_filter(‘upload_mimes’, ‘allow_upload_of_additional_file_types’);

“`

With this code in place, I can upload any file type I want, even the ones that WordPress doesn’t allow by default. This gives me the flexibility to work with different types of files and make my WordPress site even more powerful.

Hey there! Let me show you how to add the TinyMCE editor to the post excerpt’s textarea in WordPress. It’s super simple, I promise!

First, open up the “functions.php” file in your WordPress theme. Then, copy and paste the code snippet below into the file:

function addUploadMimes($mimes) {

$mimes = array_merge($mimes, array(

‘tmbundle tmCommand tmDragCommand tmSnippet tmLanguage tmPreferences’ => ‘application/octet-stream’

));

return $mimes;

}

add_filter(‘upload_mimes’, ‘addUploadMimes’);

All right, now you’re ready to go! Go ahead and save the changes to the “functions.php” file.

Once you’ve done that, the TinyMCE editor will magically appear in the post excerpt’s textarea. This means you can now use all the handy formatting and styling options that TinyMCE offers when editing your post excerpts, just like you would when writing a regular blog post.

How cool is that? Happy editing!

I’m going to show you how to make some cool changes to your website using HTML and CSS. Don’t worry, it’s not as complicated as it sounds! Just follow these steps:

Step 1: Open your “functions.php” file in the theme editor.

Step 2: Copy and paste the following code into your “functions.php” file:

“`function tinymce_excerpt_js() {

add_action(‘admin_head-post.php’, ‘tinymce_excerpt_js’);

add_action(‘admin_head-post-new.php’, ‘tinymce_excerpt_js’);

}

function tinymce_css() {

echo ‘

#postexcerpt .inside#postexcerpt .inside p #postexcerpt #excerpteditorcontainer {

border-style: solid;

padding: 0;

}

‘;

}

add_action(‘admin_head-post.php’, ‘tinymce_css’);

add_action(‘admin_head-post-new.php’, ‘tinymce_css’);“`

Step 3: Save the file.

That’s it! You’ve successfully added some new features to your website. Now you can take advantage of post formats and show post thumbnails in edit post and page overviews. Have fun exploring these creative options for your themes!

In WordPress version 2.9, they added a cool feature called Post Thumbnail. I think it’s pretty awesome. If you want to display the post thumbnail in Edit Post and Page Overview, you can use the code below. You can either put it in a Plugin or copy it into the functions.php file of your theme.

if ( !function_exists(‘fb_AddThumbColumn’) && function_exists(‘add_theme_support’) ) {

add_theme_support(‘post-thumbnails’, array( ‘post’, ‘page’ ) );

}

function fb_AddThumbColumn($cols) {

$cols[‘thumbnail’] = __(‘Thumbnail’);

return $cols;

}

function fb_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 );

break;

}

}

if ( isset($thumb) && $thumb )

echo $thumb;

else

echo __(‘None’);

}

}

// for posts

add_filter( ‘manage_posts_columns’, ‘fb_AddThumbColumn’ );

add_action( ‘manage_posts_custom_column’, ‘fb_AddThumbValue’, 10, 2 );

// for pages

add_filter( ‘manage_pages_columns’, ‘fb_AddThumbColumn’ );

add_action( ‘manage_pages_custom_column’, ‘fb_AddThumbValue’, 10, 2 );

8. Creating Custom Post Status Messages in the Admin Panel

Hey there! Have you ever wanted to display custom messages for each post you create? Well, I’ve got a tweak just for you! Originally created by a developer as a way to help clients, this tweak allows you to customize messages like “rejected,” “error,” “source,” “final,” and more for your posts. And the best part? It’s super easy to do!

add_filter(‘display_post_states’, ‘custom_post_state’);

function custom_post_state($states) {

global $post;

$show_custom_state = get_post_meta($post->ID, ‘_status’);

if ($show_custom_state) {

$states[] = ” . $show_custom_state[0] . ”;

}

return $states;

}

add_action(‘post_submitbox_misc_actions’, ‘custom_status_metabox’);

function custom_status_metabox() {

global $post;

$custom = get_post_custom($post->ID);

$status = $custom[“_status”][0];

$custom_status = array(‘Spelling’, ‘Review’, ‘Errors’, ‘Source’, ‘Rejected’, ‘Final’);

echo ”;

echo ‘Custom status: ‘;

echo ‘Custom status’;

echo ‘—————–‘;

for ($i = 0; $i < count($custom_status); $i++) {

if ($status == $custom_status[$i]) {

echo ” . $custom_status[$i] . ”;

} else {

echo ” . $custom_status[$i] . ”;

}

}

echo ‘
‘;

}

add_action(‘save_post’, ‘save_status’);

function save_status() {

global $post;

if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) {

return $post->ID;

}

update_post_meta($post->ID, “_status”, $_POST[“status”]);

}

add_action(‘admin_head’, ‘status_css’);

function status_css() {

echo ‘

.default.custom .custom_state {

font-size: 9px;

color: #666;

background: #e5e5e5;

padding: 3px 6px 3px 6px;

-moz-border-radius: 3px;

}

.spelling .review .errors .source .rejected .final

‘;

}

9. Limit Maximum Post Title Length

Hey there! I’ve got a neat trick for you to try out. If you want to control how long your post titles can be in WordPress, you can use this handy piece of code. Just add it to the functions.php file in your theme, and you’re good to go!

function maxWord($title) {

global $post;

$title = $post->post_title;

if (str_word_count($title) >= 10 ) { //set this to the maximum number of words

wp_die( __(‘Error: your post title is over the maximum word count.’) );

}

}

add_action(‘publish_post’, ‘maxWord’);

10. Change the Font in the WordPress Editor

Hey, guess what? You can change the font in the WordPress editor! If you’re not a fan of the current font, no worries. You can switch it up to something more modern, like Monaco or Consolas. Just copy and paste the following code into your WordPress theme’s functions.php file, and voila!

I have a code snippet for you that can automatically add a custom field to your page or post when it gets published. To make this work, you’ll need to add the code below to the “functions.php” file in your theme’s folder. Just make sure to replace the “custom field name” with the actual name you want to use.

function change_editor_font() {

echo “<style type=’text/css’> #editorcontainer textarea#content {

font-family: Monaco, Consolas, \”Andale Mono\”, \”Dejavu Sans Mono\”, monospace;

font-size: 14px;

color: #333;

} </style>”;

}

add_action(“admin_print_styles”, “change_editor_font”);

11. Automatically Add a Custom Field Upon Post/Page Publication

Here’s a code snippet that will automatically add a custom field to your page or post as soon as you publish it. To use it, just follow these steps:

  1. Locate the “functions.php” file in your theme’s folder.
  2. Add the code snippet provided below to the “functions.php” file.
  3. Remember to change the “custom field name” in the code to the actual name you want to use for your custom field.
  4. Save the changes.

And that’s it! Now, whenever you publish a new page or post, the custom field will be automatically added. Enjoy!

12. Say Goodbye to Unused Post Revisions

Hey there! I’ve got a nifty trick to help you clean up your WordPress database. It’s a simple SQL query that will zap away all those unnecessary post revisions and their associated metadata. But before we dive in, make sure you backup your database, just to be safe!

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

13. Customize Excerpt Length Based on Category

Have you ever wanted to adjust the length of an excerpt depending on the category you’re in? Well, I’ve got some good news for you – it’s totally doable! To make this happen, all you need to do is copy and paste the following code into your functions.php file. Just remember to change the category ID on line 3:

add_filter(‘excerpt_length’, ‘my_excerpt_length’);

function my_excerpt_length($length) {

if(in_category(14)) {

return 13;

} else {

return 60;

}

}

14. Stop Automatic Post Saving

If you find yourself in a situation where you don’t want WordPress to automatically save your post while you’re editing it in the dashboard, I’ve got you covered. Follow these simple steps: open your functions.php file and copy and paste the following code:

function disableAutoSave() {

wp_deregister_script(‘autosave’);

}

add_action( ‘wp_print_scripts’, ‘disableAutoSave’ );

Once you’ve saved the file, WordPress will no longer autosave your posts. If you want to revert back to the automatic saving function, simply delete the code.