Articles of variables

Locating Global Variables

I am now the admin of our company site using WordPress. We’d like to change some things on the home page, but unfortunately the items we want to change seem to be built in to the theme. I want to change the text overlay of our image slider. I’ve found the HTML that displays the […]

Count the number of times the search form template gets included on a page

I’ve got a template that has a search form in several locations. Each search form is identical, containing a text input, two radio buttons, two labels associated to the radio buttons, and a submit button. This works fine for the first call to get_search_form(), but on subsequent calls clicking on the labels change the first […]

Pass PHP variable to JavaScript without inline JS

So everybody and their mother says to use wp_localize_script to pass PHP variables client side. Even though the function is not actually made for this purpose, everybody does it. Kind of like Q-Tips: not made for cleaning ears, everybody does it anyways. With technology moving forward and people generally against things inline I don’t want […]

stop the_permalink printing and save as variable?

Is there a way i can get the_permalink as a variable? I need to build an info window with it but it wont appear in the $infoWindow variable… <? $link = the_permalink($post->ID); // prints out into html $infoWindow = ‘<div><h2><a href=”‘.$link.'”>’.$post->post_title.'</a></h2></div>’; ?> <script type=”text/javascript”> marker = [<?=$v_latitude?>, <?=$v_longitude?>,””,'<?=$infoWindow?>’]; locations.push(marker); </script> best, Dc

Why does a variable work on the front page but return NULL on all other pages?

Hey all. For my theme, I have multiple sidebars. Each sidebar file has a variable of $sidebar_id assigned to it. So, for sidebar-1.php, $sidebar_id = 1, for sidebar-2.php, $sidebar_id = 2, and so on. Each sidebar has an action hook inside of it. Then I write a function to hook on to the sidebar action […]

Add classname comment template from functions.php

I want to add an extra classname to my comment template (the div wrapper before the post itself) which is stated in functions.php. The classname in functions.php is an extra field in my users profile section and I want to get that string and add it as an extra classname in my comment template. The […]

Accessing $post variable from template part

Here is a section of code that I have in a template file — to display sub-navigation if the page has child-pages: <?php // display sub-nav if page has children ?> <?php $children = get_pages(array(‘child_of’ => $post->ID)); ?> <?php if (count($children)) : ?> <ul class=”nav nav-tabs”> <?php foreach ($children as $val) : ?> <li role=”presentation”> […]

Why (and how?) is get_header() erasing all my stuff?

I have a page.php in which I am defining a custom sub-menu to pass to header.php. I’ve tried using a constant (clumsy, I know): define(“CUSTOM_MENU”, “<ul><li>Test</li></ul>”); right after this, the code is including the header: get_header(); In the header.php file, where the sub menu is, I am outputting either the custom sub-menu (if set), or […]

Set cookie using GET variable

I need to set a cookie based on a GET variable so my customers can get a coupon code on our site even if they move around after selecting the coupon link. I am using the code here: Gravity Help to populate the coupon field based on the cookie. Just the second half of the […]

How to declare a JS variable in an AJAX call

I’m using: wp_localize_script( $handle, $namespace, $variables ); to declare some variables before the initial AJAX call is made, but I imagine I can’t do the same thing again within a callback function? I need to declare a newly created ID for use in another function, what’s the best way?