• Hi,

    Im hoping for some guidance. I am building a site and the owners of the site want to have a graphic for when something is working (an image of a green light) and then an image for when something is not working (an image of a red light).

    I can easily upload both images and explain to them how to insert code for whichever image they need at the time, but it seems way to complicated.

    So…Is there a way to create some sort of command (java script?) where there would be some sort of switch or command to change the image to the correct image?

    Should I be creating a custom shortcode (no idea how to do this)?

    am I overthinking this problem? is there an easy solution?

    any guidance/advice would be Greatly appreciated.
    Jeremy

Viewing 7 replies - 1 through 7 (of 7 total)
  • Yeah I think shortcodes would be the best for clients. They are pretty simple and involve only having to remember [shortcode1][shortcode2] rather than how to enter media and place it into the post. Which isn’t too hard… but if they have trouble with it perhaps shortcode would be better.

    Shortcode API

    If you still have trouble after reading that and need more of an explanation I suggest youtube, there’s tons of videos about how to create your own shortcode. Remember this only replaces the shortcode with actual code. So if you just go into a post that already includes the images and click on the text editor rather than visual editor you can see the HTML code you need to place in the shortcode function.

    it will be something like <img src="https://example.org/image.jpg" align="right" />

    Not totally sure of all the code involved, but I perceive a ‘form’ with a ‘checkbox’ that the ‘user’ could modify as needed (click a check box). Since there are so many methods of doing such a project, one would need to pick a base language to code and add to site.

    Of course, one would then need to program for ‘when something is working’.

    function myShortCode() {
    	ob_start();
    	?> <HTML> <here> ... <?PHP
    	return ob_get_clean();
    }

    is the basic function you perhaps should look at doing.

    However if you are familiar with php, like PVWD suggested above then editing the ‘editor page’ to include 2 radio buttons for ‘broken’ and ‘works’ would also be a good idea and decide on a default value.

    or I think it’s just

    function myShortCode() {
    	<HTML> <here>
    	return ;
    }

    for short html inserts.

    Oh there’s a handy link to shortcode generator at the bottom of that page:
    Shortcode Generator

    Thread Starter jmerr59944

    (@jmerr59944)

    garratt,

    where do I put that function?

    if I go PVWD’s route, do you think there’s a plug in for that or does it need to be coded from scratch?

    Jeremy

    That depends on whether or not you’re using a child theme or base theme.

    Typically functions.php however once the wp-core is next updated you loose the work you have done in that file. So it’s best to have your own functions file you can add tweaks to that doesn’t get overridden when WordPress updates. I think there should be a file called “extras.php” or “tweaks.php” which you can find in the ‘inc’ folder.

    If you are using a child theme then simply creating a “functions.php” file in your child theme folder will allow you to use custom functions without them getting overridden by the parent themes. I believe this is correct, you will need to research how to call this correctly. But hopefully someone else can clarify if this is right and how to do it.

    Alternately, and probably the better option, if you follow the guide over at WPBeginner: how-to create a site specific plugin

    You can just create your own plugin to add all these snippets and bits and pieces you find lying around the web.

    function functionName() {
    	<HTML> <here>
    	return ;
    }
    add_shortcode( 'shortCodeName', 'functionName' );

    edit; note the additional “add_shortcode();” call that I missed in earlier posts, required for adding the function to the shortcode API

    in regards to the plugin for radio buttons, you’d need to code that from scratch more than likely.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Do I need to create a custom shortcode?’ is closed to new replies.