Categories
Tech

Using Advanced Custom Fields to create Post Titles

Advanced Custom Fields - Post Title

I often need to create post titles in WordPress based on fields I’ve generated using Advanced Custom Fields. Below is an example that assumes we have a Custom Post Type registered to “staff” and two Custom Fields with the name of “first_name” and “last_name”. Using the “update_value” hook provided by Advanced Custom Fields and “wp_update_post” I am able to update the Slug and Post Title using the values given in the respective fields.

// Create Title and Slug
function acf_title( $value, $post_id, $field ) {
if ( get_post_type( $post_id ) == 'staff' ) {
$new_title = get_field('first_name', $post_id) . ' ' . $value;
$new_slug = sanitize_title( $new_title );
// update post
wp_update_post( array(
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug,
) );
}
return $value;
}
add_filter( 'acf/update_value/name=last_name', 'acf_title', 10, 3 );

Disabling the title at a custom post type level will, unfortunately, remove the clickable permalink below the title that I often use. To combat that I create a very simple metabox with the permalink. Demonstrated below.

/**
* Adds a meta box
*/
function simple_meta_box() {
add_meta_box( 'prfx_meta', ( 'View Post' ), 'simple_meta_box_callback', 'staff', 'side', 'high' );
}
add_action( 'add_meta_boxes', 'simple_meta_box' );
/**
* Outputs the content of the meta box
*/
function simple_meta_box_callback( $post ) {
echo '<a href="';
the_permalink();
echo '" class="button button-small" target="_blank">View Profile</a>';
}

Categories
Tech

5 Free Plugins Everyone With a WordPress Site Should Be Using

I have been developing WordPress sites for a long while now and have found a handful of plugins I couldn’t live without. I list them below in no particular order. I would love to hear what some of your must have plugins are in the comments.

WordPress SEO by Yoast

Do you like traffic to your site? Do you not have WordPress SEO by Yoast install? WHAT IS WRONG WITH YOU GO INSTALL AND CONFIGURE IT NOW! WordPress SEO by Yoast is the go to plugin to optimize your site for search engines. Easily edit page titles and meta descriptions, create xml sitemaps, modify robots meta, clean up your head section and much more. Also Yoast just partnered with the web security company Sucuri so you know it is legit!

Download Here

Stream

Update 4/30/15: I am putting this one on the bench for a while, will revisit soon.

Ever have a team member or client change something on your site, but can’t figure out exactly what, where, or when? Well Stream solves all of that by tracking every little move you make inside of WordPress including auto updates and displays the data in an easy to read and filterable manner. Never again will can a client call up yelling that you broke something on their site when in reality they uninstalled a key plugin.

Download Here

iThemes Security

Update 4/30/15: I have since found iThemes Security to be a bit buggy, I recommend reading the Hardening WordPress info as well as developing and maintaining a tip top WordPress install.

Somewhere out there is a someone or something trying to ruin your day right now. Hackers, bots, malware, and a slew of other nasty bullshit is trying to destroy all your hard work. Protect yourself with iThemes Security. iThemes Security protects your site against brute force attacks, common WordPress security flaws, banns known offenders, detect file changes, and so much more! If you are running a site without this plugin installed you are asking to be hacked. Just do me a favor and install it right now.

Download Here

WooSidebars

They way sidebars and widgets are currently handled in WordPress could use an overhaul. They have since outgrown their original purpose and are now being used to serve up large amounts of dynamic and custom content on a per situation basis. While WordPress core has done little to assist in these features a handful of plugins have come to ease the pain. I have used a fair amount of plugins to handle custom widget areas ( Display Widgets / Sidebar & Widget Manager ) none have been as simple and lightweight as WooSidebars.

Download Here

Akismet

Akismet is an anti-spam plugin that comes installed on every WordPress site installed. So why are so many of us guilty of never activating it? Is it because it requires you to associate it with a WordPress.com account which would take a whole 5 minutes of your life to sign up for? I guess you just like huge amounts of spam piling up in your database filled with malicious links and link bate galore? I will admit from an agency perspective it is a little bit of a pain to set up Akismet on every single site we build, but it’s benefits surpass that folly.

Download Here