• Resolved NiallASD

    (@niallasd)


    Hi all,

    I have a (Javascript) drop-down list that I include on a large number of pages on my site, using the list people can navigate between pages – every 3 months I add another page to that list.

    Is there a way I can compile the code in Code Snippets and include a shortcode on each page rather than having to update each page individually?

    Hope that makes sense!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hello,

    Can I ask how you are currently including the dropdown list on your website? Is it code that you include in the post editor?

    Thread Starter NiallASD

    (@niallasd)

    I was using the plugin Easy Code Manager, but it hasn’t been updated in a while so I’m trying an alternative.

    That plugin let me place a form (my list, consisting of months to choose from) and Javascript into it and I could then set a shortcode that I could add to any page I wanted.

    I’m currently looking at making my own custom shortcode. I placed my form and javascript into it’s own PHP file and called it in functions.php with include(‘bulletin.php’); but that just adds the drop-down list to the corner of every page. I don’t know how to make a shortcode from it to position it on a certain area of a page.

    Plugin Author Shea Bunge

    (@bungeshea)

    Hey,

    Assuming that bulletin.php contains the content you want to output, you can write a shortcode like this:

    add_shortcode( 'bulletin', function () {
    	ob_start();
    
    	include trailingslashit( WP_CONTENT_DIR ) . 'bulletin.php'
    
    	return ob_get_clean();
    } );

    You will of course need to adjust the path to the bulletin.php file appropriately.

    Thread Starter NiallASD

    (@niallasd)

    Does that go into each page or do I add that to functions and refer to it by inserting a shortcode into each page?

    Plugin Author Shea Bunge

    (@bungeshea)

    You can add the code I posted as a snippet, and then use this shortcode in each post or page:

    [bulletin]

    Thread Starter NiallASD

    (@niallasd)

    That works now.

    Thanks so much!

    Plugin Author Shea Bunge

    (@bungeshea)

    Glad to hear!

    I have a similar problem. I had a plugin called “PHP Code For Posts” that is broken and I’m trying to readd 36 radio feeds to your plugin using Shortcodes.

    Their code was:

    <?php
    include “http://audiojournalfeeds.net/tg.htm&#8221;;
    ?>

    and I named them [php snippit=1] then placed that on the page.

    I’m trying to do this with your plugin. What I’m trying is not working.

    Can you help? My client feeds radio shows to the blind at https://audiojournal.net.

    Deb Perugi

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi Deb,

    You could try something like this:

    add_shortcode( 'audio_feeds', function () {
    	$response = wp_remote_get( 'http://audiojournalfeeds.net/tg.htm' );
    
    	if ( is_array( $response ) ) {
    		return '<ul>' . $response['body'] . '</ul>';
    	}
    	
    	return 'The feed could not be retrieved.';
    } );

    After adding this as a snippet, you should be able to use the [audio_feeds] shortcode in your posts and pages.

    Thank you. There are 36 different feeds. tg.htm is just one. How do I set them apart on each page if the short code uses [audio_feeds] for each? [audio_feeds_1] and then [audio_feeds_2] ?

    I just tried that and it worked!! I am using numbers at the end to sort out all 36 of the feeds.

    Plugin Author Shea Bunge

    (@bungeshea)

    You can make one shortcode work for all different feeds, if that would make things easier. What do the other feed URLs look like?

    <?php
    include “http://audiojournalfeeds.net/tg.htm”;
    ?>

    and then each shortcode was added to the plugin list. They were named [code_snippet_1], [code_snippet_2], etc., which were placed on the page we wanted each program.

    Plugin Author Shea Bunge

    (@bungeshea)

    Okay, so if http://audiojournalfeeds.net/tg.htm is the URL to the first feed, what do the URLs to the other 35 look like? Just a number added to the end, like http://audiojournalfeeds.net/tg1.htm?

    Success. Thank You!

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Shortcodes’ is closed to new replies.