WordPress.org

Ready to get started?Download WordPress

Forums

want to create wordpress gallery link ending with hashtag (5 posts)

  1. Waqas
    Member
    Posted 1 year ago #

    Can anyone help me to make a function for wordpress attachments url ending with hashtag eg. #image

    I think I need to apply filter etc

  2. Aaron
    Member
    Posted 1 year ago #

    Can you explain this more?

    Do you just want to append #image onto every attachement URL? For example a final output would be.

    wp-content/uploads/picture.jpb#image

    May I ask why also? Might be a better way.

  3. Waqas
    Member
    Posted 1 year ago #

    sorry I didn't explained clearly. I want to change slug.

    http://sitename.com/post-name/attachement-name-2/

    to

    http://sitename.com/post-name/attachement-name-2/#image

  4. Aaron
    Member
    Posted 1 year ago #

    I am not good at regular expressions and all that good stuff so I would need to fix it by trial and error.

    But it would be something like below adding to functions.php

    add_action('generate_rewrite_rules', 'attachment_rewrite_rule_14924');
    function attachment_rewrite_rule_14924($wp_rewrite){
      $new_rules = array();
      $new_rules['attachment/(\d*)$'] = 'index.php?attachment_id=$matches[1]';
      $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }

    My first attempt would be changing it to

    $new_rules['attachment/(\d*)$#image']

    Like I said I suck at regular expressions so I can't help you anymore than this.

  5. Waqas
    Member
    Posted 1 year ago #

    Aaron Nimocks

    Thanks for the tip. I tried but it didn't work. No errors and no effect to urls.

Topic Closed

This topic has been closed to new replies.

About this Topic