Articles of include

wp_star_rating() – Adding a 5 star rating system to theme

My goal is to add a 5 star rating system to my theme. I read that there’s a function wp_star_rating in wp-admin/includes/template.php on line 2121, that I’ve been trying to use for the ratings. I am using WP 4.0. Just using wp_star_rating() in my theme’s content.php alone returns: Fatal error: Call to undefined function wp_star_rating() […]

Include Class File in WordPress

I’m including a Class file in functions.php file require_once get_template_directory() . “/core/classes/General.php”; require_once get_template_directory() . “/core/classes/User.php”; When I do $user->getCredits($user_id); in some page, it works fine. But when I tried doing that same line of code in header.php it prompts an error of Call to a member function getCredits() on null. So what I did […]

require_once not working

I have a custom page template, and this template need to include one php file. I tried to put this script require(‘…/hc-v2-child/ayah.php’) and this require(__DIR__.’ayah.php’); in functions.php and in the custom page template, but I’m getting this error [07-Oct-2015 04:15:21 UTC] PHP Fatal error: require_once(): Failed opening required ‘/folder/folder1/public_html/folde3/wp-content/themes/hc-v2-childayah.php’ (include_path=’.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear’) in /folder/folder1/public_html/folde3/wp-content/themes/hc-v2-child/page-mylogin.php on line 51

using `require` in my functions.php breaks the site

So, I have a snippet of code I’d like to tidy away in a directory that’s close to the root my wordpress directory. Specifially it lives in /includes/inc. I’ve created a file called test.php and within it it simply says echo “XXXX”; All I currenly want to be able to do is include this file […]

Having trouble linking to file using relative path

I’ve created a widget plugin and have placed the code for displaying the front end content in a separate file. I’m linking to the file using include_once but keep getting the error, failed to open stream: No such file or directory in… The plugin folder contains 2 subfolders: includes and tpls The file I’m linking […]

How can I include an external file in a post or page?

I have some text blocks which are used various times. I want to be able to add them as txt files to a folder in my theme, and then add one to specific posts and pages with either a shortcode or include. I’ve found various plugins which don’t work (deliver ‘failed to open, no such […]

Can I include a custom PHP function in a WordPress function?

I’m trying to add a shortcode in my WordPress functions.php file. I want the short code contents to be sent to a PHP function from another part of the website. This is the code: function short_api($atts){ include (__DIR__.’/api/short_look_up.php’); $api_info = get_api_info($atts); return $api_info; } add_shortcode(‘apii’, ‘short_api’); (The get_api_info() is a function in short_look_up.php) Is this […]

Passing variables to template parts

I have one template file videos.php which has the following line of code in it (aswell as a load of HTML): <?php get_template_part(‘loop’, ‘feed-videos’ ); ?> inside that template part, I have the following: <?php $video = ‘video-‘ . $post->ID; ?> <?php get_template_part( ‘include’, ‘modal-video’ ); ?> I would then like to be able to […]

How to get the form code from the edit page of a specific post?

On a site I’m working on, in the profile page – for example – I have to display the content from a few custom posts (additional details, location details, billing). And instead of having the user click Edit and change the page to the ‘edit page’ for that particular post and then come back to […]

Unable to point the child theme directory even using get_stylesheet_directory()

I am developing a child theme based on storefront as parent theme. I am trying to include files in child theme functions.php file as: require_once get_stylesheet_directory() . ‘/inc/_customizer.php’; require_once get_stylesheet_directory() . ‘/inc/_header.php’; When I move any function from functions.php file to _header.php or _cuztomizer.php files which are in the inc folder in the child theme […]