different template for first and second level custom post page

i needed something similar and i’ve come up with this simple little function that make things easier : function is_child_post($parent_ID = null) { global $post; if (isset($parent_ID) && $parent_ID != null){ return $post->post_parent == $parent_ID; } return $post->post_parent > 0; } Usage: check if a post/page/custom has a parent: if (is_child_post()){ //yes we have a … Read more

how to include javascript file and css file in wordpress

WordPress already ships with jQuery. There is no need to include it in your theme. Javascript Let’s say your jquery.tabify.js file is located in /js/jquery.tabify.js in your theme. Include the following code in your functions.php file: function jquery_tabify() { wp_enqueue_script( ‘jquery-tabify’, get_template_directory_uri() . ‘/js/jquery.tabify.js’, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, ‘jquery_tabify’ ); This will … Read more

get_stylesheet_uri returns wrong path

I don’t think you want get_stylesheet_uri, which will return the complete stylesheet URL including style.css. You want get_stylesheet_directory_uri, which will give you the path up to the child/parent theme stylesheet directory but not the trailing style.css, and which is the function used by the Roots theme per the code you posted. wp_enqueue_style(‘fsc’, get_stylesheet_directory_uri().’/abcdefg.css’, false, null); … Read more

Style every second widget?

Use the dynamic_sidebar_params filter. The following code adds classes to say whether the widget is odd or even, what index it is in the sidebar, and what sidebar it’s in. Note: the str_replace(“class=\””, “class=\”$class “, $before_widget); code below depends on your before_widget using double quotes — it probably should be done with a regular expression … Read more

Why are my styles being applied to the admin area?

Why are my styles being applied to the admin area? Assuming that is all of the code, it is because you are enqueueing the styles globally. You need to hook that to wp_enqueue_scripts, which will only load on the front end. wp_register_style( ‘main-styles’, get_stylesheet_directory_uri() . ‘/css/styles.css’, false, ‘1.0.0’, ‘all’); function enqueue_script_front_wpse_84975() { wp_enqueue_style(‘main-styles’); } add_action(‘wp_enqueue_scripts’, … Read more

Different background-image by category

You can do this using WordPress’s handy body_class() function. Depending on whether and how it is used in your theme, it may already be giving you what you need. Here’s how to find out: Check the source of your page to see if the <body> tag in your category archive pages has any classes containing … Read more