Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know this general question has been asked before (like here and here), but the problem is with my limited experience, I cannot get the results I need looking at other people's code. So here's my question: What is the best way to change the breadcrumb link "Explore" on this page: http://example.com/explore/photos/

from this: http://example.com/explore/explore/ to this: http://example.com/explore/ ?

I know this is a bit of a hack - but with my current theme I believe it would be the easiest way to get things working the way I want.

The way my current theme is setup, I have a custom post type of gallery, to which I made the slug to be "explore" (to match my site's menu hierarchy). But then, in order to get the "photos" to correctly show up in the hierarchy in breadcrumbs using the SEO Yoast plugin (from what I understand though, the plugin just follows Wordpress when it comes to permalinks), I had to add a gallery category parent of "explore". So all I want to do it "fake" the url of http://example.com/explore/ whenever http://example.com/explore/explore/ is shown. Ideally, this would happen server side as the breadcrumb is written, so when I mouseover the link in the breadcrumb, http://example.com/explore/ would be shown.

share|improve this question
    
Could you please use example.com for questions? First all links anyway have rel="nofollow", second it's good practice and easier to read. Thank you! –  kaiser Oct 14 '12 at 19:43
1  
Yes I will update it. I used my real site so that people could see the real issue - but then after I found an answer I was going to go back and rename the links, but I forgot. Thanks. –  Nathan Oct 15 '12 at 4:04
add comment

1 Answer 1

So I ran across this page here and decided to try it out one more time. And it worked!

I was able to make the gallery custom post type be a child to a "Photos" page which is child to "Explore" and everything turned out perfect in the breadcrumbs using this code in functions.php (customized "casestudy" to my custom post type name):

//Add the meta box callback function
function admin_init(){
add_meta_box("case_study_parent_id", "Case Study Parent ID", "set_case_study_parent_id", "casestudy", "normal", "low");
}
add_action("admin_init", "admin_init");

//Meta box for setting the parent ID
function set_case_study_parent_id() {
  global $post;
  $custom = get_post_custom($post->ID);
  $parent_id = $custom['parent_id'][0];
  ?>
  <p>Please specify the ID of the page or post to be a parent to this Case Study.</p>
  <p>Leave blank for no heirarchy.  Case studies will appear from the server root with no assocaited parent page or post.</p>
  <input type="text" id="parent_id" name="parent_id" value="<?php echo $post->post_parent; ?>" />
  <?php
  // create a custom nonce for submit verification later
  echo '<input type="hidden" name="parent_id_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
}

// Save the meta data
function save_case_study_parent_id($post_id) {
  global $post;

  // make sure data came from our meta box
  if (!wp_verify_nonce($_POST['parent_id_noncename'],__FILE__)) return $post_id;
    if(isset($_POST['parent_id']) && ($_POST['post_type'] == "casestudy")) {
      $data = $_POST['parent_id'];
      update_post_meta($post_id, 'parent_id', $data);
    }
}
add_action("save_post", "save_case_study_parent_id");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.