Anything Popup Shortcode

Below, you’ll find a detailed guide on how to add the Anything Popup Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Anything Popup Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Anything Popup Plugin and the shortcodes it provides:

Plugin Icon
Anything Popup

"Anything Popup is a versatile WordPress plugin that allows you to create and manage custom popups on your website. Enhance user experience with personalized messages and notifications."

★★★★✩ (26) Active Installs: 5000+ Tested with: 6.1.4 PHP Version: false
Included Shortcodes:
  • [AnythingPopup id="1"]

Anything Popup [AnythingPopup] Shortcode

The AnythingPopup shortcode is a versatile tool for creating pop-up elements on your WordPress site. It fetches data from the AnythingPopupTable and generates a pop-up based on the attributes provided. The shortcode can display a specific pop-up by ID, or a random one if “RANDOM” or no ID is specified. The pop-up’s content, dimensions, colors, and other settings are customizable. This shortcode also includes the necessary CSS to style the pop-up and its components. It generates a link to open the pop-up and a close button within the pop-up. If no matching data is found, it simply returns a ‘No record found’ message.

Shortcode: [AnythingPopup id="1"]

Parameters

Here is a list of all possible AnythingPopup id=”1″ shortcode parameters and attributes:

  • id – Represents the unique ID of the popup content.

Examples and Usage

Basic example – Display a specific popup by referencing its ID.

[AnythingPopup id="1"]

Advanced examples

Display a random popup. If there are multiple popups in the database, this shortcode will select one at random each time the page is loaded.

[AnythingPopup id="RANDOM"]

Display a specific popup by referencing its ID, but if no popup with that ID exists, a random popup will be displayed instead.

[AnythingPopup id="9999"]

Note: In this example, assuming there is no popup with the ID of 9999, a random popup will be displayed because the code checks if the ID is numeric and if there is no record with that ID, it defaults to displaying a random popup.

PHP Function Code

In case you have difficulties debugging what causing issues with [AnythingPopup id="1"] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'AnythingPopup', 'AnythingPopup_shortcode' );

Shortcode PHP function:

function AnythingPopup_shortcode( $atts ) 
{
	global $wpdb;
	$scode = "";
	// [AnythingPopup id="1"]
	if ( ! is_array( $atts ) )
	{
		return '';
	}
	$pop_id = $atts['id'];
	
	$sSql = "select * from ".AnythingPopupTable." where 1=1";
	if($pop_id == "RANDOM" || $pop_id == "")
	{
		$sSql = $sSql . " Order by rand()";
	}
	else
	{
		if(is_numeric($pop_id)) 
		{
			$sSql = $sSql . " and pop_id=$pop_id";
		}
	}
	$sSql = $sSql . " LIMIT 0,1";
	
	$pop = "";
	$data = $wpdb->get_results($sSql);
	if ( ! empty($data) ) 
	{

		$data = $data[0];
		$pop_content_id = $data->pop_id;
		$pop_width = stripslashes($data->pop_width);
		$pop_height = stripslashes($data->pop_height);
		$pop_headercolor = stripslashes($data->pop_headercolor);
		$pop_bordercolor = stripslashes($data->pop_bordercolor);
		$pop_header_fontcolor = stripslashes($data->pop_header_fontcolor);
		$pop_title = stripslashes($data->pop_title);
		$pop_Temp = stripslashes($data->pop_content);
		$pop_Temp = do_shortcode($pop_Temp);
		$pop_content = $pop_Temp;	
		$pop_content = str_replace("\n", "<br />", $pop_content);
		$pop_caption = stripslashes($data->pop_caption);
		$pop_content_height = $pop_height - 60;
		
		//echo $pop_content;
		
		$pop = $pop . '<style type="text/css">';
		$pop = $pop . '#AnythingPopup_BoxContainer'.$pop_content_id.'	{';
			$pop = $pop . 'width:'.$pop_width.'px;';
			$pop = $pop . 'height:'.$pop_height.'px;';
			$pop = $pop . 'max-width:80%;';
			$pop = $pop . 'background:#FFFFFF;';
			$pop = $pop . 'border:1px solid '.$pop_bordercolor.';';
			$pop = $pop . 'padding:0;';
			$pop = $pop . 'position:fixed;';
			$pop = $pop . 'z-index:99999;';
			$pop = $pop . 'cursor:default;';   
			$pop = $pop . '-moz-border-radius: 10px;';
			$pop = $pop . '-webkit-border-radius: 10px;';
			$pop = $pop . '-khtml-border-radius: 10px;';
			$pop = $pop . 'border-radius: 10px;   ';
			$pop = $pop . 'display:none;';
		$pop = $pop . '} ';
		$pop = $pop . '#AnythingPopup_BoxContainerHeader'.$pop_content_id.' {';
			$pop = $pop . 'height:30px;';
			$pop = $pop . 'background:'.$pop_headercolor.';';
			$pop = $pop . 'border-top-right-radius:10px;';
			$pop = $pop . '-moz-border-radius-topright:10px;';
			$pop = $pop . '-webkit-border-top-right-radius:10px;';
			$pop = $pop . '-khtml-border-top-right-radius: 10px;';
			$pop = $pop . 'border-top-left-radius:10px;';
			$pop = $pop . '-moz-border-radius-topleft:10px;';
			$pop = $pop . '-webkit-border-top-left-radius:10px;';
			$pop = $pop . '-khtml-border-top-left-radius: 10px;';   
		$pop = $pop . '} ';
		$pop = $pop . '#AnythingPopup_BoxContainerHeader'.$pop_content_id.' a {';
		   $pop = $pop . 'color:'.$pop_header_fontcolor.';';
		   $pop = $pop . 'font-family:Verdana,Arial;';
		   $pop = $pop . 'font-size:10pt;';
		   $pop = $pop . 'font-weight:bold;';
		$pop = $pop . '} ';
		$pop = $pop . '#AnythingPopup_BoxTitle'.$pop_content_id.' {';
		   $pop = $pop . 'float:left;';
		   $pop = $pop . ' margin:5px;';
		   $pop = $pop . 'color:'.$pop_header_fontcolor.';';
		   $pop = $pop . 'font-family:Verdana,Arial;';
		   $pop = $pop . 'font-size:12pt;';
		   $pop = $pop . 'font-weight:bold;';   
		$pop = $pop . '} ';
		$pop = $pop . '#AnythingPopup_BoxClose'.$pop_content_id.' {';
		   $pop = $pop . 'float:right;';
		   $pop = $pop . 'width:50px;';
		   $pop = $pop . 'margin:5px;';
		$pop = $pop . '} ';
		$pop = $pop . '#AnythingPopup_BoxContainerBody'.$pop_content_id.' {';
		   $pop = $pop . 'margin:10px;';
		   $pop = $pop . 'overflow:auto;';
		   $pop = $pop . 'height:'.$pop_content_height.'px;';
		$pop = $pop . '} ';
		$pop = $pop . '#AnythingPopup_BoxContainerFooter'.$pop_content_id.' {';
		   $pop = $pop . 'position: fixed;'; 
		   $pop = $pop . 'top:0;'; 
		   $pop = $pop . 'left:0;'; 
		   $pop = $pop . 'bottom:0;'; 
		   $pop = $pop . 'right:0;';
		   //$pop = $pop . 'background:#000000;';
		   $pop = $pop . 'opacity: .3;';
		   $pop = $pop . '-moz-opacity: .3;';
		   $pop = $pop . 'filter: alpha(opacity=30);';
		   //$pop = $pop . 'border:1px solid '.$pop_bordercolor.';';
		   $pop = $pop . 'z-index:999;';
		   $pop = $pop . 'display:none;';
		$pop = $pop . '} ';
		$pop = $pop . '</style>';
		
		$HrefOpen = 'javascript:AnythingPopup_OpenForm("AnythingPopup_BoxContainer'.$pop_content_id.'","AnythingPopup_BoxContainerBody'.$pop_content_id.'","AnythingPopup_BoxContainerFooter'.$pop_content_id.'","'.$pop_width.'","'.$pop_height.'");';
		$HrefClose = "javascript:AnythingPopup_HideForm('AnythingPopup_BoxContainer".$pop_content_id."','AnythingPopup_BoxContainerFooter".$pop_content_id."');";
	
		$pop = $pop . "<a href='".$HrefOpen."'>".$pop_caption."</a>";
		$pop = $pop . '<div style="display: none;" id="AnythingPopup_BoxContainer'.$pop_content_id.'">';
		  $pop = $pop . '<div id="AnythingPopup_BoxContainerHeader'.$pop_content_id.'">';
			$pop = $pop . '<div id="AnythingPopup_BoxTitle'.$pop_content_id.'">'.$pop_title.'</div>';
			$pop = $pop . '<div id="AnythingPopup_BoxClose'.$pop_content_id.'"><a href="'.$HrefClose.'">Close</a></div>';
		  $pop = $pop . '</div>';
		  $pop = $pop . '<div id="AnythingPopup_BoxContainerBody'.$pop_content_id.'">'.$pop_content.'</div>';
		$pop = $pop . '</div>';
		$pop = $pop . '<div style="display: none;" id="AnythingPopup_BoxContainerFooter'.$pop_content_id.'"></div>';
	}
	else
	{
		$pop = __('No record found.', 'anything-popup');
	}
	return $pop;
}

Code file location:

anything-popup/anything-popup/anything-popup.php

Conclusion

Now that you’ve learned how to embed the Anything Popup Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *