• Hey everyone!

    I currently have my WordPress SEO Titles & Metas > Post Types > Posts > Title template settings as such: %%title%% · %%category%%.

    However I need some more flexibility with listing the categories, as the WordPress SEO just stacks the categories next to each other without the option of excluding or re-ordering. Basically I’m looking to use code I’ve written on my own. Is there an easy way to bypass WordPress SEO’s title template to inject my own code? Can I just paste my function in the field?

    Thanks in advance!

    http://wordpress.org/extend/plugins/wordpress-seo/

Viewing 1 replies (of 1 total)
  • Thread Starter ggg377

    (@ggg377)

    I figured I should get into wordpress-seo/inc/wpseo-functions.php and modify either of those lines: 1) ‘%%category%%’ => wpseo_get_terms( $r->ID, ‘category’ ), 2)

    function wpseo_get_terms( $id, $taxonomy, $return_single = false ) {
    	// If we're on a specific tag, category or taxonomy page, return that and bail.
    	if ( is_category() || is_tag() || is_tax() ) {
    		global $wp_query;
    		$term = $wp_query->get_queried_object();
    		return $term->name;
    	}
    
    	if ( empty( $id ) || empty( $taxonomy ) )
    		return '';
    
    	$output = '';
    	$terms  = get_the_terms( $id, $taxonomy );
    	if ( $terms ) {
    		foreach ( $terms as $term ) {
    			if ( $return_single )
    				return $term->name;
    			$output .= $term->name . ', ';
    		}
    		return rtrim( trim( $output ), ',' );
    	}
    	return '';
    }

    Basically I’m thinking of modifying the code to allow the insertion of my custom php function somewhere in there.

    Lets say the code is something like this:

    <?php
    foreach((get_the_category()) as $category) {
        if ($category->cat_name != 'hot') {
        echo '' . $category->name. '';
    }
    }
    ?>

    Where would I insert this? Please help :'(

Viewing 1 replies (of 1 total)

The topic ‘Use custom function for post title template?’ is closed to new replies.