WordPress.org

Forums

Better Internal Link Search
[resolved] Adding shortcuts (7 posts)

  1. simoreds
    Member
    Posted 1 year ago #

    Hi, I need more information on how to modify the file functions.php to add shortcuts. This is the feature I'd use the most for this plugin but I simply can't find any documentation on how to do it.

    Thank you very much.

    https://wordpress.org/plugins/better-internal-link-search/

  2. Brady Vercher
    Member
    Plugin Author

    Posted 1 year ago #

    Hi simoreds, you just need to drop the following filter in your functions.php and add as many entries as you'd like:

    function prefix_bils_shortcuts( $shortcuts ) {
    	$shortcuts['name'] = array(
    		'title'     => 'Shortcut Title',
    		'permalink' => 'http://example.com/',
    	);
    
    	return $shortcuts;
    }
    add_filter( 'better_internal_link_search_shortcuts', 'prefix_bils_shortcuts' );

    Here's what you need to update:

    1. Update the function prefix to be unique
    2. Change the 'name' key to something unique that identifies your shortcut
    3. Update the 'Shortcut Title'
    4. Insert your own URL for the permalink value
  3. simoreds
    Member
    Posted 1 year ago #

    Hi Brady,

    Thank you very much for your reply.

    I tried to do what you said but it didn't work, I'm sure I've done something wrong, I'm quit newby to wp so please forgive me.. ;)

    I added the filter to the bottom of the file function.php and changed the few parameters you told me to modify, here's the last bit of the page with at the end your script:

    .....

    if ( $reset && $encodings ) {
    		$encoding = array_pop( $encodings );
    		mb_internal_encoding( $encoding );
    	}
    }
    
    /**
     * Resets the mbstring internal encoding to a users previously set encoding.
     *
     * @see mbstring_binary_safe_encoding()
     *
     * @since 3.7.0
     */
    function reset_mbstring_encoding() {
    	mbstring_binary_safe_encoding( true );
    }
    function prefix_simo_shortcuts( $shortcuts ) {
    	$shortcuts['tuscany'] = array(
    		'title'     => 'Tuscany',
    		'permalink' => 'http://www.gate-away.com/property_region.php?region=16',
    	);
    
    	return $shortcuts;
    }
    add_filter( 'better_internal_link_search_shortcuts', 'prefix_simo_shortcuts' );

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    Please can you tell me where I did it wrong and can you make also a sample on how to do it and how to add other shortcuts?

    Thank you very much

  4. Brady Vercher
    Member
    Plugin Author

    Posted 1 year ago #

    I copied that snippet directly into a custom plugin and it looks like it's working fine. Did you try typing "tuscany" in the link popup on a post or page?

    You can type "shortcuts" as well and it'll show in the list of all shortcuts.

    If you want to add more, just duplicate that $shortcuts variable:

    $shortcuts['tuscany'] = array(
    	'title'     => 'Tuscany',
    	'permalink' => 'http://www.gate-away.com/property_region.php?region=16',
    );
    
    $shortcuts['sicily'] = array(
    	'title'     => 'Sicily',
    	'permalink' => 'http://www.gate-away.com/property_region.php?region=xx',
    );

    If you have a bunch of links that follow that same convention, you might want to look into creating a modifier instead. That's more involved, so you'll have to read the source to see how those are created.

  5. simoreds
    Member
    Posted 1 year ago #

    Hi again, actually it is not that it didn't work but it actually gave me a fatal error when opening the blog page:

    Fatal error: Call to undefined function add_filter() in /var/www/vhosts/gate-away.com/httpdocs/news/wp-includes/functions.php on line 4202

    that was by doing what I pasted in my previous post

  6. Brady Vercher
    Member
    Plugin Author

    Posted 1 year ago #

    That's a core file and you shouldn't be modifying it. When anyone mentions functions.php in WordPress, they're referring to the file your your active theme. If it's not a theme you've built, you don't really want to modify that either, because your changes will be lost if the theme updates.

    The only two places you should be adding your own code snippets are via a child theme's functions.php or in a custom plugin. I'd recommend that latter for changes that aren't design related so that you maintain the functionality when switching themes. It's also makes it easier to reuse on other sites.

    With that in mind, here's a sample plugin you can use as your base.

  7. nedalturab
    Member
    Posted 7 months ago #

    hi every body

    i want to add shortcut to the Adminer plugin in my wordpress blog so
    that some users can modify a specific database, is it possible and how?
    Best regards

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Better Internal Link Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic