error in getting post id

On a default install of WP you get always the ID of a post with the function get_the_ID(). Id dosnt work this you go about the global var: $post. echo $GLOBALS[‘post’]->ID Is this not enough, then go about the global wp_query $GLOBALS[‘wp_query’]->post->ID;

Function naming convention

I almost used the same convention as @GhostToas but to me I usually use classes to minimize conflict. For internal or company project: class MyCompany_Classname {} For Client specific project: class ClientProject_Classname {} Using a class will absolutely help you avoid conflicts and thus, you can name your function using generic function names. Say for … Read more

Function that outputs second theme url

You can use two inbuilt functions to do this. switch_to_blog get_stylesheet_directory_uri You can use both in the following way to make a function out of it which would give you the url to the theme. Put the below in the functions.php file function wpse_get_theme_url( $blog_id = 1 ){ switch_to_blog( $blog_id ); $template_url = get_stylesheet_directory_uri(); restore_current_blog(); … Read more

What’s wrong with my use of plugin_url()?

function add_my_css_and_my_js_files(){ wp_enqueue_script(‘jquery-validate-min’, plugins_url(‘activate/jquery_validate_min.js’, __FILE__ ) ); } add_action(‘wp_enqueue_scripts’, “add_my_css_and_my_js_files”); You need to use the plugins_url() function (you are missing the s at the end of plugins). Reference the location of the script file with the relative path. Meaning the path should be activate/jquery_validate_min.js.

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