Help With Creating Shortcode

It seems that extract() function sets it to false if value is not provided. There might be a better way around it, but I’ve used workaround as follows function Test($atts) { extract(shortcode_atts(array( ‘row’ => null ), $atts)); $output=”false”; if( in_array(‘row’, $atts)) $output=”true”; return $output; } add_shortcode(“test”, “Test”);

different style sheet for just one page template

The preferred way is to use add_action( ‘wp_enqueue_scripts’, ‘themeslug_enqueue_style’ ); within your child theme functions.php file or directly in your referral.php template page. Either way, it’s by using add_action and not by echoing into the <link> tag. Registering your style is also a recommended practice. The one benefit I would see in your case is … Read more

Optimizing a WordPress site

Functions and shortcodes that are never used, eat some processor time at launch, as WP is registering their existence. Deregistering them would take up some additional (and minimal) processor time. Because they are loaded with functions.php they will reside in memory, either registered or deregistered. Which amounts to the same, as the code is never … Read more

Load Post into DIV with Ajax

First of all you need to register a action callback for you ajax request. Secondly you need to send all ajax request to wp-admin/admin-ajax.php (both GET and POST). And lastly you need to modify your javascript a little to pass the action parameter which will trigger the callback. and var post_link = $(this); doesn’t gives … Read more

Need help getting a function to function

Your code is based on jQuery and you are including it to a PHP file. So you need to call it between <script></script> tag and obviously either you must end and start PHP tags before <script> and after </script> or echo the full script. Now come to how you are gonna execute the code. You … Read more

Use .php file as page instead of wordpress page & template file?

Yes you can do this but creating template like usercp.php . (1) First create usercp.php template and then this one line at first of template. update_post_meta(get_the_ID(), ‘usercp’, 111); (2) Then create page and assign template. (2) Then go to your functions.php file and add this code add_action(‘template_redirect’, ‘setPrivateTemplate’); function setPrivateTemplate() { if (get_post_meta(get_the_ID(), ‘usercp’, true) … Read more

Echo a function inside a function

echo is a PHP language construct which pushes values to the output buffer. It does not have a return value, so concatenating it with a string would cause everything after the echo to immediately be sent to the output buffer, and everything prior to echo to compose the concatenated string. This is such a misuse … Read more