php – finding wordpress function location-ThrowExceptions

Exception or error:

I’m a little bit new to WordPress. Recently I developed a WordPress website using V magazine-Lite theme and working on customizing the theme.

In the template files, I found out that it is calling a function called “vmagazine_lite_before_body_content” which is not defined any of the template files (I did a file content search)

<?php do_action( 'vmagazine_lite_before_body_content' ); ?>

Where I’d be able to find this function.

How to solve:

You can think of the “do_action” function as not “calling” the function, but as establishing it – or, more properly, creating the action hook. You won’t find it anywhere else (usually) because this will (typically) be the unique position for that hook.

You can create a new function or functions to initiate when that hook is encountered, like so:

add_action( 'vmagazine_lite_before_body_content', 'woah_nelly_that_there_content' ) ; 

function woah_nelly_that_there_content() {

   echo 'Woah, Nelly!' ;

}

So that’ll place “Woah, Nelly!” presumably before the body content in V Magazine Lite, however V Magazine Lite defines it.

WordPress Handbook: Actions

Leave a Reply

Your email address will not be published. Required fields are marked *