Seagyn Davis
Strict Standards: Only variables should be passed by reference

Strict Standards: Only variables should be passed by reference

Reading time of post 1 min readDate when post was published8 August 2014
Disclosure: Some of the links in this post are affiliate links, meaning that if you click on one of the links and purchase an item, I may receive a commission. All opinions however are my own and I do not accept payments for positive reviews. This is just a little way for me to monetize the time I spend writing for you.

I recently came across an interesting warning on one of my WordPress sites. The warning was "Strict Standards: Only variables should be passed by reference" and was referring to line 14. As you can see below, I wasnt' really sure what the issue was here.

if ($post->post_parent != 0) { // On child page $postID = array_pop( get_post_ancestors( $post ) ); // Seagyn's Code - get highest level $parentTitle = get_the_title($postID); $parentTitle = strtolower(str_replace('.', '', $parentTitle)); $parentTitle = strtolower(str_replace(' ', '-', $parentTitle)); }

After a big of research, I found that array_pop requires an array in a variable as the functions is initiated with a reference variable which means the function will return the last item in the array and update the passed variable without the last item. PHP.net have a great example that explains this further.

To fix my issue, I had to update line 14 as follows:

if ($post->post_parent != 0) { // On child page $ancestors = get_post_ancestors( $post ); $postID = array_pop( $ancestors );// Seagyn's Code - get highest level $parentTitle = get_the_title( $postID ); $parentTitle = strtolower(str_replace('.', '', $parentTitle)); $parentTitle = strtolower(str_replace(' ', '-', $parentTitle)); }

Hope this helps you!

The following companies make my life awesome, maybe they'll make yours awesome too?