How to access static files from inside Wordpress plugin directory - php

I'm trying to create a custom Wordpress Plugin for one of my websites. And I've created a shortcode inside the plugin and I have one .swf file inside the plugin directory that I want to embed using the created shortcode. I've tried with <embed src="wp-content/plugins/myplugin/obj.swf"> also tried with <iframe> but I get 404 Page not found error. The same error when I try to open the swf file directly from the browser's address bar. Can anyone give me little hand how can I achieve this?

Based on our comments, and the screen shot, you should rename the folder on the server to be in lower case (ie from falja-e-namazit-WP to falja-e-namazit-wp).
EDIT
Not sure what you mean by your latest comment, but you should be able to get the URL of your asset using the plugins_url() function. Assuming your SWF file is in /wp-content/plugins/falja-e-namazit-wp/assets, the following code (in /wp-content/plugins/falja-e-namazit-wp/falja-e-namazit-wp.php) should return its URL:
$swf_url = plugins_url( 'assets/falja.swf', __FILE__ );

Related

How to add(include) elementor created page in theme file 404.php

I created a page using elementor(named as: 'Error-page'), currently using linoor theme. What I want is to load this 'Error-page' via theme's default 404.php file (NOT using any plugin). Should I just type in 'include Error-page.php' in 404.php file to make it work?
Meta: My goal is to show my custom error page which I created using elementor(named as: Error-page) when invalid url is typed. One way of doing it is using plugin(I prefer not to do this for the time being), 2nd way could be somehow including this custom page in theme's default 404.php file
Note: Im new to wordpress
after thinking about your question, i have 2 solutions for you:
1. if you do not have code knowledge
This way is simple and safer, but have limits than other way - it's not using your template but redirect viewer to your template page. Any way, the same result
Build the 404 template with Elementor and publish it
Open your theme's 404.php file
In the very first top of the template file **(below <?php tag) paste this code:
wp_redirect( '/your-template-slug' );
exit;
Save it and you're done
2. If you have basic code knowledge:
This way is a litle complex, but it alow you to using not for 404 file - but other templates (archive, categories...)
Install "Anywhere Elementor" plugin
Build the 404 template as you do with Elementor
Get your template php shortcode
Edit the theme's 404.php file to echo out your template
In case you need more detail guide, i have record a step by step guide video here

Am I using Wordpress incorrectly?

I am new to web dev with WP. I just realized that I made my front page (it has a form to be filled out by a user) by putting the code for it in a php file (through CPanel) and using <?php include() ?> to use that php file in my index.php. However, I just noticed that WP has a Pages section where I can add code by simply surrounding it with <code></code>. What is the best practice here? Am I under-using the CMS that is Wordpress by not using this Pages section? Or is it ok to not use it?
you can use some pulgins to use php code in pages like "allow-php-in-posts-and-pages" . and if you want some php file then you have create a template for that and that temmplate should be add in wp-page .

Replace Logo Image on Drupal Site

I'm new to Drupal and to PHP, all I need to do is change the image file for the logo in my header. I've found my page.tpl.php, and the line for the link, but I don't understand what $logo is referencing. What file is it pointing to? How to I find it and change the file?
Thanks, in advance.
It's point to your {your_theme}/logo.png.
But if system cannot find that png file on your theme.
It will use default logo, for example: themes/bartik/logo.png.
You should not do that in page.tpl.php. Just login to your site, choose appearance => choose your active theme => settings => upload file => go to your file and click upload => save.
Drupal will automatically set $logo to the place it uploaded your logo (somewhere in your public folder). It is important for your theme to use this variable in order to show it on your website. Since you found the variable in your page.tpl.php file, that should be fine.
If you really want to change the file rather than use the proposed method, do this method once and simply search for the logo file in your public folder. Next time you can overwrite this file. You should not overwrite the default Drupal logo.
An even better way to get it is by opening the source code when looking at your webpage (your browser provides this, you can also use a tool like firebug) and search for the "header" id. On the next lines you should find the relative path to the image file that is currently used.
If you are using default theme, you can change your logo at
[your project folder>themes>your theme>logo.png]
If you are using custom theme, you can change at
[your project folder>sites>all>themes>your themes>logo.png]
$logo is referencing to logo.png on those directories.

Linking to a template file relatively in Wordpress

I am trying to run a ajax post script from the header of a wordpress site on an action.
I am currently using
bloginfo('template_directory')
to get a link to where the script is. But the above currently outputs
http://domain.com/wp-themes/path/to/file.php
but what I need to run the script is the relative version
../../../wp-themes/path/to/file.php
and ths will be different depending on the depth of the post / page.
Is there a modifier in wordpress anywhere to make this happen.
The 'template_directory' attribute for the bloginfo() function will always return a URL.
You were probably looking for something like
get_template_directory()

Wordpress calling an HTML file from PHP

I am trying to modify a theme on wordpress. The theme shows a slider on the front page, which reads from the featured.php file.
I have gone into the featured.php and removed all the PHP code. I can inject my custom HTML into the featured.php and the pages display properly, however I want the page to display from a wordpress page.
So i tried to:
<?php
$html = file_get_contents('http://www.mydomain.com/homepage-featured');
?>
The above link corresponds to a page i created in wordpress. So i want to be able to inject my HTML into that page and then when you load my homepage, the PHP tells the browser to display the contents of this URL.
The above code doesn't work.
Thanks for the help.
file_get_contents() - as its name suggests - reads a file in but does not print it. You need to echo your $html variable. A better way is to use require() or include() but if I were you I would put my custom file on the same server so that way you don't have to use the file from a remote location thus sparing network traffic.
I think you have better to use the include function.
The file_get_contents you are using would generate an HTTP request, so it would make your script slower. I think it would be a good idea to put the HTML file on the same server if possible.
Have you tried
<?php
require('http://www.mydomain.com/homepage-featured');
?>
If my understanding is correct, you are trying to use a template (featured.php) for a different page other than the front page.
To do so, just change the Page Template of the page(the separate page which is # www.url.com/myhomepage). You can change this # Dashboard > Pages (Click Edit link in the required page) > Edit Page > Page Attributes meta box (available in the rightside below Publish) > Template. Change the template of this page to "Featured".
(I assume that your code in file feature.php has Template Name: Featured at the top)

Categories