0

I need a special behavior in the title, so I use shortcodes there, the display is fine (I just use filters the_title&single_post_title), however when permalink is generated, the shortcode stays there (it just strips out the [ ] )...

I need to somehow change the source title before the link is generated,
since I don't want to do/recreate the permalink logic again.

Note: When I used HTML directly instead of shortcodes, the desired result is delivered :) (HTML is stripped, but its inner contents are kept). However, that is unacceptable for a regular user case.

0

You should be able to use a plugin and set your shortcode as a stop word. Search for a "SEO slugs" plugin that lets you add your own "stop words" and you should find several possibilities.

From there, anything that is inside your shortcode needs to be added as a stop word, which will not be included in the final published slug.

You may be able to check the source code of these plugins and incorporate something similar in your own plugin - it would be best to include this type of code in your own plugin, so your own code prevents the conflict, but be sure to namespace it so that if the end user ever installs one of these SEO Slugs plugins, it won't cause a conflict.

  • Hello, thank you for your answer, can you be more specific please? (there are lots of them) – jave.web Jun 16 '17 at 8:12
  • Plugin recommendations are off topic. Try a few out and see what works for your particular configuration. – WebElaine Jun 16 '17 at 13:28
  • I am not asking you for a recommendation, but for being more specific, since you've already suggested some plugins - I am sure I won't go through ALL plugins found for these keywords, if you name a list of plugins which you are sure can do this, that would be nice :) Anyway I am looking for a programming way to do this and I have a feeling that plugins will have their own link building, which is something I am trying to avoid.... – jave.web Jun 16 '17 at 17:18
0

Lately I've found out that, the link is generated through get_sample_permalink() which uses sanitize_title() ... and there is a filter "sanitize_title" - provided with a lots of useful info :)

add_filter( 'sanitize_title', function( $title, $raw_title, $context ){
  $title = do_shortcode($title);

  return $title; //filter => must return!
}, 1, 3 ); //top priority (1), 3 arguments accepted

From what is seems to me sanitize_title() basically prepares title for an ID generation - removes html, php, and accents.

Note: $title provided to filter has already gone through process of removing accents - if you want the original - just use $raw_title as source ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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