Display Custom Field Value on Admin Page Column

The main errors where the missing of the $post_ID parameter in page_template_field and using $custom_field_id instead of $post_ID. Anyway, this works and is simpler: add_filter(‘manage_pages_columns’, ‘column_page’); function column_page($defaults) { $defaults[‘column_template’] = ‘Page Template’; return $defaults; } add_action(‘manage_pages_custom_column’,’column_page_template’,10,2); function column_page_template($column_name, $post_ID) { if ($column_name == ‘column_template’) { $custom_field_values = get_post_meta($post_ID,’page_template’); if (!empty($custom_field_values)) { echo ‘<p> ‘. … Read more

jQuery does not work

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. … Read more

Get ID of first image attached to a post

I assume all your code is wrapped inside the loop? And you should check that a post does indeed have attachments before operating on the $images array: while ( have_posts() ) { the_post(); if ( has_post_thumbnail() ) { the_post_thumbnail( /* No need for “post-thumbnail” argument, it’s the default. */ ); } else { // No … Read more

check if the user is owner of current page

Per the Codex, is_author() checks to see if you’re on an Author Archive page (ie, a page listing all the posts/pages/etc that a given user has authored). If you’re on any other type of page, is_author() will return false. What you’re looking for sounds more along these lines: if ( in_the_loop() ) { get_currentuserinfo(); print … Read more

Why doesn’t is_page(id) work in functions.php?

is_page() relies on a complete global $wp_query object. If you call it before the action template_redirect has been fired, it might be impossible to get that data. Wait for a proper action. Example: add_filter( ‘template_include’, function( $template ) { if ( is_page( 27 ) ) echo ‘this is the apply page’; return $template; }); You … Read more

Fatal error: Call to a member function get_page_permastruct() on a non-object

The WordPress environment is not yet fully initialized when your plugin files are loaded, it’s almost always too early to safely run code that interacts with core at that point. WordPress achieves its initial state through a process which contains its own set of actions and filters, so plugins load before that happens to allow … Read more

Option Tree integration of Custom CSS

never* execute code outside of hooks as you are more likely to call a function or use a variable before they were declared and initialized. your code should be function css() { if (ot_get_option(‘css’, false) != false) { echo'<style>’.ot_get_option(‘css’).'</style>’; } } add_action( ‘wp_head’, ‘css’, 100 ); *never say never, but this is a rule to … Read more

is there a benefit in using a constant over get_stylesheet_directory_uri?

You can read up the source code of theme.php where get_stylesheet_directory_uri() is defined, inside you’ll see a str_replace() wich is consuming additional resources on each request. The best way to avoid this is to define a variable or constant that contains the path. In that case it is only called once. https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/theme.php#L0