Correct code to use php in text widget

I think this is enough, inside the widget-function of your Widget-class. ob_start(); eval( ‘?>’ . $html ); $html = ob_get_contents(); ob_end_clean(); Alternative use a maintenant plugin for this job, like PHP Code Widget

Use of IF statement in Header file

As Maruti Mohanty mentioned you might not be using get_template_part in the correct way. The first argument is the slug name for the generic template. The second argument is the name of the specialized template. So currently your code is doing the following: On the page that has the ‘custom-page’ slug, display the template part … Read more

Using php inside javascript [closed]

If you want to re-instantiate your countdown timer only after the date has been changed and saved, then, something to the effect of: //In your custom.js file…. //make sure your localized data is a dependency of your custom.js file so you have proper scope to local data jQuery(document).ready(function($){ var date, gapinvite; date = $(‘input[name=”director_date”]’); if … Read more

How to echo the_title from an array of posts?

try to use get_posts instead , as I read in http://codex.wordpress.org/Function_Reference/query_posts you can use this code: global $post; $args = array(‘posts_per_page’ =>3,’category’ => 3 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); the_title() endforeach; wp_reset_postdata(); Regard’s.

Remove Post if Advanced Custom Field is checked to fix paging

Use WP_Query instead, and you can use the meta_key / meta_value parameters: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘cat’ => 10, ‘paged’ => $paged, ‘posts_per_page’ => 12, ‘post_status’ => ‘any’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘archived’, ‘meta_value’ => ‘true’ ); $posts = new WP_Query($args); ?> <?php while($posts->have_posts()): $posts->the_post(); ?> <?php … Read more

Retrieve Plugin Settings and insert into XML string

You don’t need the echo when you are concatenating strings. Just remove it. $xmlInputData=”<?xml version=”1.0″ encoding=”utf-8″ ?><data><settings><origin=””. $my_options[‘origin’] .'” username=”‘. $my_options[‘user’] . ‘” password=”‘. $my_options[‘password’] . ‘” /></settings><enquiries><lead productName=\”Appointment Booking”><customer><name>’. $_REQUEST[‘first-name’].’ ‘. $_REQUEST[‘last-name’].'</name><email>’. $_REQUEST[’email’].'</email><postcode>’. $_REQUEST[‘postal’].'</postcode><houseNumber></houseNumber><address></address><city></city><region></region><tel>’. $_REQUEST[‘phone-number’].'</tel><mobile></mobile><notes></notes></customer></lead></enquiries></data>’;

Get All In One SEO Pack to use custom field instead of Content

You can not specify which field, but you can use the filter *aioseop_description* to do whatever you want with the description before presenting. So technically, you can use your custom field as follows (untested) : add_filter(‘aioseop_description’,’my_custom_description’); global $post; function my_custom_description($text) { $mycustomseo = get_post_meta($post->ID, ‘my_custom_field’, true); return $mycustomseo; } Replace *my_custom_field* with your custom field. … Read more