loading a php file to a specific page id

I'm trying to assign a php file to a specfic page? I have modals stored in different files and want have them load in when their assigned page is called. These pages are using the same theme, "Portfolio". If I do something like: <?php $id="page-id-8229"; include '/modals/work/cplfModals.php';?> for each file in my Portfolio template, each page will still load all of the modals that are assigned, not just the one that I'm try to assign to that page. Is there …
Category: Web

ABSPATH not working! Any idea why?

This is what in my wp-config.php : if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); I am calling from plugin/pluginName directory to : require_once( ABSPATH . 'wp-includes/user.php'); But it is returning: Warning: require_once(ABSPATHwp-includes/user.php) [function.require-once]: failed to open stream: No such file or directory in /home/------/wp-content/plugins/---/---.php on line 43 Fatal error: require_once() [function.require]: Failed opening required 'ABSPATHwp-includes/user.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/------/wp-content/plugins/---/---.php on line 43 Any idea why I am having this error? Any solution? Thanks.
Category: Web

Displaying page content from plugin, inside exising empty WP page

Old php developer here, very.. very new to WP, so be kind. I am building my first WP Plugin. I have this in the plugin central file (the one that is /plugins/my_plugin/my_plugin.php): // Setup the admin management page function wx_admin_burger_management() { add_menu_page( 'Burger Manager', // Page title 'Burger Manager', // Menu title 'manage_options', // Capability 'admin-manage-burger', // Menu slug 'wx_burger_admin', // Callback function 'dashicons-list-view', // Menu icon '3' // Priority ); } function wx_burger_admin() { include(trailingslashit(WX_PLUGIN_PATH).'my-burger-admin.php'); } add_action('admin_menu', 'wx_admin_burger_management'); This …
Category: Web

get_option() not returning expected value from plugin

I am trying to make my first plugin, and so far everything has been fine except one little annoying thing. I have my fields setup and updating data and looks just fine in my database: mfwp_settings | a:1:{i:test;s:3:"response";} But when I want to echo the value for 'test' in my Admin Panel it comes back blank or NULL. It echos fine on a front end page but within the the plugin it wont retrieve the data using the following: $mfwp_opt …
Category: Web

Include tags from array, ignore the rest in get_the_tags

I'm trying to exclude a large amount of tags from being displayed in get_the_tags function. I have successfully excluded tags using this code: <?php $links = array(); foreach (get_the_tags() as $this_tag) { if ($this_tag->name != "test1" && $this_tag->name != "test2"){ $links[] = '<a href="'.get_tag_link($this_tag->term_id).'" title="'.$this_tag->name.'">'.$this_tag->name.'</a>'; } } echo implode(' • ', $links); ?> However, the issue is there's new tags added regularly, and having to manually modify the exclude code isn't something i want to do, can i somehow specify …
Category: Web

load/require specific php files for specific pages/templates/post types

I have a plugin with multiple php files. I want to load some of them only when specific template files are loaded. I don't want to load everything. Currently, I'm doing it with add_action( 'wp', 'load_files' ) , but it means actions defined in the additional php files are not being done. Any ideas? EDIT: Seems like there is some of work around, by getting the id from the url, like this What's the earliest point I can get the …
Category: Web

How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?

In a plugin I am currently coding, I want to use the Simple HTML DOM Parser library. However, when I include it require(CPS_PLUGIN_PATH . '/vendor/simple_html_dom.php'); I get this error: Fatal error: Cannot redeclare file_get_html() (previously declared in /www/htdocs/12345/mydomain.com/wp-content/plugins/custom-post-snippets/vendor/simple_html_dom.php:48) in /www/htdocs/12345/mydomain.com/wp-content/plugins/fast-velocity-minify/libs/simplehtmldom/simple_html_dom.php on line 54 So obviously the Fast Velocity Minify plugin is already using it. What do I do here, if I don't want to mess around in the library itself? What's the best practice in a case like this?
Category: Web

Pull in an "Include" file based on a WordPress Category ID

Here's what I am trying to achieve: when a category page is loaded then, based upn the ID of that category, an "include" file is loaded. I believe that the below would work for some limited text, but I would prefer to load an "include" file b/c it will have multiple paragraphs and I feel it is better to manage that way. <?php $catarray = get_the_category( $post->ID ); foreach ($catarray as $cat) { $catid = $cat->term_id; if ($catid == 10) …
Category: Web

Can I have an additional functions.php file in Wordpress?

There're quite a lot of functions, and so, does my theme, it all gets a little cluttered even with all the comments. Additionally, every time the theme is updated, the new functions.php file would replace the current one. So, it becomes a pain. Hence, I thought, would it be possible to have a 2nd/3rd functions.php file? Using PHP include or require function. That way, I can categorise the functions and they won't be affected on theme update. So, <?php include …
Category: Web

Why should I use get_template_directory() when include files?

When I include files in wordpress I noticed that include works fine without get_template_directory(). Include even works fine without parenteses. include( get_template_directory() . '/includes/front/enqueue.php' ); works fine as well as include '/includes/front/enqueue.php'; Could anyone please explain, should I use get_template_directory() when inlcude files in wordpress? And is it "ok" to not use parentheses after include?
Category: Web

Wordpress functions.php conditional include another functions file

In my wordpress functions.php I have calls to include other function files. For example like so: include("functions/articles.php"); include("functions/custompost.php"); Within those files I have all my functions that pertain to specific pages on the site. What I want to do is this: //Articles custom functions function articles_fn() { if ( is_page_template( 'page_templates/articles.php' ) ) { include("functions/articles.php"); } } add_action( 'init', 'articles_fn'); //CustomPostType custom functions function cpt_fn() { if ( is_page_template( 'page_templates/custompost.php' ) ) { include("functions/custompost.php"); } } add_action( 'init', 'cpt_fn'); ...but …
Category: Web

Include files in functions.php

This is a rewritten post since the way I worded my old post totally confused everyone. MikeSchinkel shows how he uses Include files in his theme's functions.php file In this Stackexchange post: Organizing Code in your WordPress Theme's functions.php File? Example: require_once('includes/my-file.php'); How would you write this php line if the file to include is inside a directory, inside the wp-content directory? Location: [wordpress install]/wp-content/new-directory/my-file.php The only way I can think of is like this: require_once( ABSPATH . '/wp-content/new-directory/my-file.php' ); …
Category: Web

FPDF for creating pdf diplomas

Before anything else, I must say I am new on building WordPress functions. I have a website with online courses. Students have to sit exams and at the end they get a score, an average of all the exams. I am trying to build a simple dynamic PDF diploma with their name and average score, no more, which I will download by clicking on a button from a table/list. I found the class FPDF, unzipped it and uploaded it through …
Category: Web

Include PHP file in Content using [shortcode]

Here is what I have I am not having any lucking finding how to simply include a file in the content editor using a shortcode. For Example if I wanted to include form.php inside my Contact Page how would I make this happen using a shortcode? Below is was attempting to work with to no avail. Any help would be appreciated! // Shortcode implementation function magic_stuff($atts) { // turn on output buffering to capture script output ob_start(); // include file …
Category: Web

The proper way to include/require PHP files in WordPress

I'm a new WordPress developer and recently I've been having problems (on multiple sites) with include_once and require_once for PHP files. If I include (get_theme_directory_uri() . 'subdir/file') the specified file gets included (or required, which leads to fatal errors) but if any WordPress functions are called within 'file' I get something similar to: 'Call to undefined function add_action() in /full/path/to/file'. The apparent solution I've found is to do: include(dirname(__FILE__) . "/subdir/filename"); Is this right or did I miss 'the WordPress …
Category: Web

Hardening wordpress: blocking /includes with htaccess

This page https://wordpress.org/support/article/hardening-wordpress/ says this should be included in the .htaccess file to block requests for files inside the includes dir. # Block the include-only files. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^wp-admin/includes/ - [F,L] RewriteRule !^wp-includes/ - [S=3] RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L] RewriteRule ^wp-includes/theme-compat/ - [F,L] </IfModule> # BEGIN WordPress ... How does that work ? As far as I can read it, it only specifies not to rewrite certain urls (using -), and …
Category: Web

Change title and meta description in included page (not template)

I'm trying to change title and meta description for pages used for products. The goal is to have the same effect as here: <script>document.title = "<?php echo $new_title; ?>";</script> The page with lists of products is a template where are includes in some conditions. template_listing.php: if (!empty($offer['listingId'])) include('include_offer.php'); I'm struggling with how to change title/description in include_offer.php. My findings so far: function wp1_filter_wp_title($title) { if (is_page_template('include_offer.php')) { return 'some title'; } return $title; } add_filter('pre_get_document_title', 'wp1_filter_wp_title'); But it doesn't work. …
Category: Web

Add few specific post ids to wp_query

I have following args to get recent posts, $args = array( 'date_query' => array( array( 'after' => '1 week ago' ) ), 'posts_per_page' => 15, 'ignore_sticky_posts' => 1, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'cat' => '-907,-908,-909' ); Now I need include few specific Ids to same query. So I tried follows, but it doesn't work $highlights = array('8308', '8315'); $args = array( 'date_query' => array( array( 'after' => '1 week ago' ) ), 'posts_per_page' => 15, …
Category: Web

Use $variable from file1.php in file2.php (different file paths)

I have $variable_1 = '5'; in /public/includes/themes/theme-section-users-score.php and I want to use its value in another php file with a different location /plugins/name/other/users-time.php , I tried using include_once , require_once and others but I can't, might be the .htaccess doesn't allow me? please help, thanks in advance.
Category: Web

the_author() not working outside the loop

I have the following code on index.php and I want to include this line of code (bellow) to display author info on top of the loop. <?php include 'author-top.php'; ?><!--author--> I want it to display right after the header as shows here <?php get_header(); ?> <!--This is where I want my author div to display--> <?php include 'author-top.php'; ?><!--author--> <div id="primary" class="content-area"> <div id="content" class="site-content-home" role="main"> <?php if ( is_home() && ! is_paged() ) : ?> <h2 class="site-description"><?php bloginfo( 'description' …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.