Tag Info

Hot answers tagged

6

You should always add javascript (and styles) with the Wordpress function wp_enqueue_script() Works like this: wp_enqueue_script( $handle // the name of your enqueued file, in your case 'myscript' ,$src // source of your file, can be external, or for your example: get_bloginfo('template_directory') . '/js/scripts.js' ,$deps // does your javascript ...


5

There are 3 methods. Somewhat weird but since this text is internationalized you can filter the output. This is just an example to remove the text, the link is still present in the source. add_filter('gettext', 'remove_powered_by', 20, 3); function remove_powered_by( $translated_text, $untranslated_text, $domain ) { $custom_field_text = 'Proudly ...


4

I am not sure if you posted code as-is or extracted part of it, but per this snippet - you are hooking function inside itself. Which doesn't seem like it will work nicely. :) Also init hook should not be used for enqueue, on front-end hook to use is wp_enqueue_scripts, see where is the right place to register/enqueue scripts & styles. Example ...


4

You have true set in the 4th parameter (version), not the 5th. wp_enqueue_script( 'my_javascript_file', //slug get_template_directory_uri() . '/javascripts/app.js', //path array('jquery'), //dependencies false, //version ...


3

There's an in_footer parameter that you can pass to wp_enqueue_scripts - does that work? I would hook to admin_enqueue_scripts, check the $page for location, and enqueue your script there, with 'in_footer' as true. Example: add_action( 'admin_enqueue_scripts', 'enqueue_my_script' ); function enqueue_my_script( $page ) { if ($page !== 'edit.php') ...


3

If I interpret the question correctly you: Don't have any .js javascript files Output any javascript you have from an .php file (presumably code) Include this javascript on the bottom of the page by including the .php file. So you are actually doing: Correct Combining all the javascript in one file Having the javascript in the footer Minimized the ...


3

Hook into 'admin_footer-post-new.php' and 'admin_footer-post.php', check the global variable $post_type: add_action( 'admin_footer-post-new.php', 'wpse_73692_script' ); add_action( 'admin_footer-post.php', 'wpse_73692_script' ); function wpse_73692_script() { if ( 'post' !== $GLOBALS['post_type'] ) return; ?> <script>alert( ...


3

This is not an error, it is a warning. You can make this go away by: Fixing the warning Write errors to the error log instead of the screen ( best practice ) To fix the error, I recommend looking at what's hooking into wp_footer etc, or using a PHP debugger


3

I don't think there's anything fundamentally wrong with your approach, I see it pretty often. You could hook parse_request and 301 redirect any requests to footer to the front page. I wonder though how visitors would end up there in the first place, as long as you exclude it from the sitemap and don't link to it anywhere. Or you could create a custom post ...


3

This is what ended up working for me: Put your script into a .js file and then: add_action( 'login_enqueue_scripts', 'enqueue_my_script' ); function enqueue_my_script( $page ) { wp_enqueue_script( 'my-script', 'http://domain.com/path/myjs-file.js', null, null, true ); }


2

If the theme does not implement wp_footer() a lot of functionality that depends on it will break. For this reason, implementing wp_footer() is required to get your theme accepted in the WP.org directory. So it is not unreasonable to break when wp_footer() is missing. Be sure to add a notice in your FAQ that you require wp_footer() in the theme. You can also ...


2

From OP comment: The footer.php file is all encrypted Do not download Themes from random sites. Only download Themes from trusted sources, for exactly this reason. The footer is encrypted, and the Theme is probably distributed under a license that prohibits modifying the footer. Thus, for both reasons, we cannot help you.


2

First a bit of advise (since the solution is based on it) - always "enqueue" your scripts, don't just add them in the footer. Read this, for example . Now the solution for loading scripts on specific template, since this is what you asked for: function enqueue_themescrits() { if ( is_page_template('contact.php') ) { //the file your contact page uses ...


2

You've got »Conditional Tags« in WordPress. Those allow you do determine if some condition meets or not (basically those are parts of the $wp_query object, just wrapped with a public API function). In detail: There's is_page(), which tells you if you're on the desired page not. So just wrap it into a function, hook in at the right hook and abort if you're ...


2

What may be easier (if you don't necessarily want all the same menu items to appear in the footer) is to: Create a new menu, "Footer Menu" for example Add-in whatever links (pages) are needed there Add a widget (called Custom Menu) to a footer widget position (if your current theme supports it). Let me know if that helps. Thanks!


2

If you're just using a small script or other markup, you can hook a function to the wp_footer filter, which is included in all modern themes: function wpse_77196_script_in_footer() { <script language="javascript" type="text/javascript"> startcart() </script> } add_filter( 'wp_footer', 'wpse_77196_script_in_footer' ); However, if ...


2

If you are releasing a GPL'd theme (which WP requires, but not looking to start the whole GPL debate here) then you can't prevent someone from removing your footer link. You can ask they they don't do it. But anyone who's looking to do so will get around whatever method you employ. a side note: having these links in the footer may be more of a bad thing ...


2

It is incredibly bad practice to hardcode urls, almost as bad practice as hardcoded menus. I strongly suggest you research custom nav menus. It will save yourself a large amount of time in development, and support costs, and it's something to demonstrate to your client to gain kudos. Hardcoding menus is a major warning sign of poor code, and it reflects ...


1

I am unable to understand your Question but WordPress provide a good way to use java script files wp_enqueue_script() function my_scripts_method() { wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom_script.js', array('jquery') ); } add_action('wp_enqueue_scripts', 'my_scripts_method');


1

Since the gallery is rendered via a [gallery] shortcode, you can try using do_shortcode() in footer.php. For example, assuming you want to output a gallery with an ID of 1: <?php echo do_shortcode( '[gallery id="1"]' ); ?>


1

You should use dynamic_sidebar()s for that. You can read more about it in Code. They allow you to use widgets, like - for example - a custom menu widget. More about the custom menus inside wp-nav-menu.


1

The Wordpress wpdb class is a little different than the normal way of querying in that you run "vanilla" database queries. You can see documentation on the wpdb class on the Wordpress docs: http://codex.wordpress.org/Class_Reference/wpdb#Run_Any_Query_on_the_Database Also, in regard to your code, you should be able to change the line here: ...


1

Sure. Set the fifth parameter of wp_enqueue_script or wp_register_script as true, and that script will be placed in the footer. For example, your line wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.7.1'); should be wp_register_script('jquery', ...


1

You're looking for the is_home() and is_front_page() conditional tags USe it like: <?php if(is_home() || is_front_page()) : ?> <!-- Small footer on the home page, only has the #footer-navigation div --> <div id="footer-top"> <ul id="footer-navigation"> ...


1

I got your problem. You are facing problem how and where to write the code for footer. Below are some guide line it may help or give you some basic idea. First of you have to create footer.php template, if not created. Your tag should be closed in footer.php What ever code or div, links, copyright images etc you want to put u can code here. Example code ...


1

That code doesn't look like it conforms to the current Widgets API. Perhaps your problem is related? First potential issue: your class test should be plugin-slug-test, in order to avoid naming conflicts. Second potential issue: the only functions inside of your WP_Widget extending class should be: function plugin-slug-test() {} function widget( $args, ...


1

Remove the action, then add it back on a different hook. I think the only concern you could have with doing this is ensuring you do that late enough for the action to have been hooked, it should possible using the plugins_loaded hook(because that runs after plugins have loaded). add_action( 'plugins_loaded', 'juggle_sharethis_action' ); function ...


1

You can use the get_page function in your footer.php template file: <?php $footer_page = get_page($id = 147); echo apply_filters('the_content', $footer_page->post_content); ?> Alternative approaches: Create a custom menu for use in the footer. This may not be an option if you really need the flexibility of a page, but note that you can add CSS ...


1

I don't quite grasp why you'd want to include a page "on the bottom of each page", rather than putting the "logo+links+images" in the footer and creating a menu below that. That being said, in order to achieve what you want, create the page and include the following in your theme's footer.php (the below code example assumes that that page's ID is 83 and/or ...


1

You could use output buffering and append the script to the end. But you shouldn’t. It is slow. It is not safe. Some other plugin could run right before you do and compress everything to gzip. You would just invalidate the whole page in this case. The user may have removed wp_footer intentionally. Aside: </body>, the closing tag, is optional. I ...



Only top voted, non community-wiki answers of a minimum length are eligible