Is possible to add a short URL to the field list?
-
Cite plugin works wonderfully in my WordPress 4.1 website (https://opistobranquis.info/en) where we include a citation box at the end of every post with a personalized URL.
As we have pretty long URLs, the cite does not always display “nicely”.
Would be possible to include the WordPress Jetpack “Short-link” (or any other short link method) as a field in the cite?
Thank you for this useful and rock-solid plugin.
-
Hi Miquel, sorry I didn’t get to this sooner. I checked out your site and looks like you actually found a way to do this on your own? What was the method? It’s definitely a good idea which others might want to do too.
—
Thanks for your positive comments. Actually if you wouldn’t mind, it is very helpful if you can leave a review/rating here.
Hi Maeve,
Certainly I found a way to do this, it took me a certain ammount of work but it runs quite fine.
I installed the Short URL plugin by SedLex because it allows me to keep my domain in the short URL (not using anyone else’s domain).
Then I had to modify the Cite plugin code in file “cite.php”, changing the following functions to add another option called “shortlink”:
function wpcp_admin() { ?> <?php wpcp_setting_update_check(); ?> <form method="post" action="options.php"> <?php settings_fields('wpcp_setting'); ?> <?php global $wpcp_setting; ?> <div class="wpcp-admin"> <h2><?php _e('Cite Settings', 'cite') ?></h2> <p><?php _e('Help readers know how to cite your article correctly. Enter the reference text you wish to appear in the cite box using the editor below. Add the cite box to any page/post using shortcode', 'cite') ?> <code>[cite]</code></p> <p><textarea cols="80" rows="5" name="wpcp_setting[setting]" id="wpcp_setting[setting]" class="wpcp-textarea"><?php echo $wpcp_setting[setting]; ?></textarea></p> <p class="wpcp-templates-info"><span><?php _e('Available templates tags:', 'cite') ?></span><br> {author} - <?php _e('the post/page author','cite') ?><br> {title} - <?php _e('the title of your post/page', 'cite') ?><br> {sitename} - <?php _e('your site name taken from Settings > General', 'cite') ?><br> {publication_date} - <?php _e('date the page/post was published', 'cite') ?><br> {permalink} - <?php _e('the permalink of the page/post being accessed', 'cite') ?><br> {shortlink} - <?php _e('the shortlink of the page/post being accessed', 'cite') ?><br> {date} - <?php _e('the current date, if "date accessed" is desired', 'cite') ?><br> <?php _e('Also, you may insert words, HTML tags, and punctuation.', 'cite') ?><br><br> <b><?php _e('Samples', 'cite') ?></b> (<?php _e('similar to', 'cite') ?> <a href="https://www.chicagomanualofstyle.org/tools_citationguide.html" target="_blank"><?php _e('Chicago-style notes', 'cite') ?></a>):<br> <?php _e('Blog post:', 'cite') ?> {author}, "{title}," {sitename}, {publication_date}, {permalink}.<br> <?php _e('Book chapter:', 'cite') ?> {author}, "{title}," in {sitename}, ed. Jack Dougherty (Ann Arbor: Michigan Publishing, 2014), {permalink}.</p> <input type="hidden" name="wpcp_setting[update]" value="<?php _e('UPDATED', 'cite') ?>" /> <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'cite') ?>" /> </form> </div> <?php }
and
function cite_shortcode() { global $wpcp_setting; // Getting admin preferred date format for current date if(!function_exists('displayTodaysDate')){ function displayTodaysDate() { return date_i18n(get_option('date_format')); } } $find_string = array('{author}','{sitename}', '{title}', '{date}', '{publication_date}', '{permalink}', '{shortlink}'); $replace_string = array(get_the_author(), get_bloginfo('name'), get_the_title(), displayTodaysDate(), get_the_date(), '<a href="' . get_permalink() . '">' . get_permalink() . '</a>', '<a href="' . wp_get_shortlink(get_the_ID()) . '">' . wp_get_shortlink(get_the_ID()) . '</a>'); $edited_setting = str_replace($find_string, $replace_string, $wpcp_setting[setting]); return '<div class="wpcp">' . $edited_setting . '</div>'; }
I have not tried this with other shortlink plugins, but I think my changes could work with any shortlink plugin.because I use a standard WP function “wp_get_shortlink()”.
I hope this is useful for you all.
Awesome, thanks for sharing your patch Miquel. I’m sure this will be useful for anyone else stumbling across this thread in the future with similar needs.
Hello!
I was also looking for this and I found a way around it after stumbling on this thread (and some trial and error)! Thank you Miquel!
I didn’t use a Short URL plugin, but instead I’d call for the bloginfo and the article’s ID to create a custom shortlink that includes the website and not the wp.me…
Here is a summary of all changes I made in the plugin:
1. In Default Settings, I added {shortlink} after {permalink} :// Default settings $wpcp_default = apply_filters('wpcp_default_setting', array( 'setting' => __('Cite this article as: {author}, "{title}," in <em>{sitename}</em>, {publication_date}, {permalink}, {shortlink}.','cite') ));
2. I also included it in the functions like Miquel (see {shortlink}) :
// Admin page function wpcp_admin() { ?> <?php wpcp_setting_update_check(); ?> <form method="post" action="options.php"> <?php settings_fields('wpcp_setting'); ?> <?php global $wpcp_setting; ?> <div class="wpcp-admin"> <h2><?php _e('Cite Settings', 'cite') ?></h2> <p><?php _e('Help readers know how to cite your article correctly. Enter the reference text you wish to appear in the cite box using the editor below. Add the cite box to any page/post using shortcode', 'cite') ?> <code>[cite]</code></p> <p><textarea cols="80" rows="5" name="wpcp_setting[setting]" id="wpcp_setting[setting]" class="wpcp-textarea"><?php echo $wpcp_setting[setting]; ?></textarea></p> <p class="wpcp-templates-info"><span><?php _e('Available templates tags:', 'cite') ?></span><br> {author} - <?php _e('the post/page author','cite') ?><br> {title} - <?php _e('the title of your post/page', 'cite') ?><br> {sitename} - <?php _e('your site name taken from Settings > General', 'cite') ?><br> {publication_date} - <?php _e('date the page/post was published', 'cite') ?><br> {permalink} - <?php _e('the permalink of the page/post being accessed', 'cite') ?><br> {shortlink} - <?php _e('the shortlink of the page/post being accessed', 'cite') ?><br> {date} - <?php _e('the current date, if "date accessed" is desired', 'cite') ?><br> <?php _e('Also, you may insert words, HTML tags, and punctuation.', 'cite') ?><br><br> <b><?php _e('Samples', 'cite') ?></b> (<?php _e('similar to', 'cite') ?> <a href="https://www.chicagomanualofstyle.org/tools_citationguide.html" target="_blank"><?php _e('Chicago-style notes', 'cite') ?></a>):<br> <?php _e('Blog post:', 'cite') ?> {author}, "{title}," {sitename}, {publication_date}, {permalink}.<br> <?php _e('Book chapter:', 'cite') ?> {author}, "{title}," in {sitename}, ed. Jack Dougherty (Ann Arbor: Michigan Publishing, 2014), {permalink}.</p> <input type="hidden" name="wpcp_setting[update]" value="<?php _e('UPDATED', 'cite') ?>" /> <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'cite') ?>" /> </form> </div> <?php }
and most importantly in
3. Registering shortcode as
'<a href="' . get_bloginfo('url')."/?p=". (get_the_ID()) . '">' . get_bloginfo('url')."/?p=".(get_the_ID()) . '</a>'
// Registering shortcode [cite] add_shortcode('cite', 'cite_shortcode'); function cite_shortcode() { global $wpcp_setting; // Getting admin preferred date format for current date if(!function_exists('displayTodaysDate')){ function displayTodaysDate() { return date_i18n(get_option('date_format')); } } $find_string = array('{author}','{sitename}', '{title}', '{date}', '{publication_date}', '{permalink}', '{shortlink}'); $replace_string = array(get_the_author(), get_bloginfo('name'), get_the_title(), displayTodaysDate(), get_the_date(), '<a href="' . get_permalink() . '">' . get_permalink() . '</a>', '<a href="' . get_bloginfo('url')."/?p=". (get_the_ID()) . '">' . get_bloginfo('url')."/?p=".(get_the_ID()) . '</a>'); $edited_setting = str_replace($find_string, $replace_string, $wpcp_setting[setting]); return '<div class="wpcp">' . $edited_setting . '</div>'; }
Luciallo, I’m glad I inspired you on achieving your goals. Thanks for sharing this.
- The topic ‘Is possible to add a short URL to the field list?’ is closed to new replies.