• PGrizz

    (@pgrizz)


    By default WordPress takes the page title you enter in the editor and makes it into a permalink. This title is usually also the h1 of the post.

    If I keep the default title in the editor as my h1, but then add another h2 that’s added by an Advanced Custom Field, how would I be able to combine the custom h2 field into my page’s permalink to help my SEO?

    For Example: My post’s title would be “WordPress Title” and my custom h2 field added to the post would be “Example for Forum” so the url would end up being “site.com/wordpress-title-example-for-forum”

    Doesn’t seem like it’s as easy as just appending the custom field on to the end of /%postname%/ in the Custom Structure of the Permalink settings.

Viewing 6 replies - 16 through 21 (of 21 total)
  • Hi @pgrizz,

    Please check the answer posted on the ACF forum post that you have linked in last reply.

    Cheers.

    Thread Starter PGrizz

    (@pgrizz)

    @wpmu DEV

    Yeah… I saw that. Just trying to figure out how to do it now since I’ve never done it before. ??

    Thread Starter PGrizz

    (@pgrizz)

    @wpmu DEV

    I still can’t seem to get this to work… ??

    The ACF plugin dev has been trying to help, but some of his advice has been going over my head and all the changes I make based off of his suggestions aren’t working.

    Could you please have a look? As you would better understand what he’s suggesting and how to modify your original code to work with ACF.

    Link top the support thread is again here: https://support.advancedcustomfields.com/forums/topic/subheadline-text-delayed-when-publishing/

    Hi @pgrizz,

    Try removing whole previous code and add the following code in place of it.

    // Custom URL Post Title
    
    function custom_post_title( $value, $post_id, $field  )
    {
    	// update the $post via the wp_update_post function
    
    		if(isset($value) && $value != '') {
    			 $args = array(
    				 'ID'           => $post_id,
    				 'post_name' => sanitize_title(get_the_title($post_id).'-'.$value)
    			 );
    			 wp_update_post( $args );
    		} 
    
        return $value;
    }
    
    // acf/update_value/name={$field_name} - filter for a specific field based on it's name
    add_filter('acf/update_value/name=heading2', 'custom_post_title', 10, 3);
    
    // End Custom URL Post Title

    Best Regards,

    Thread Starter PGrizz

    (@pgrizz)

    Yep, that did it! Thanks again! =D

    Hi @pgrizz,

    You are welcome.

    Cheers.

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Adding a custom field in addition to Post Name to Permalinks?’ is closed to new replies.