Jump to content


This topic is now archived and is closed to further replies.


Add php to every page / every template

Recommended Posts




I need to add some code to each and every page / template. In this instance a new 'section' for the code simply won't cut it as the code is writing it's own div/content and so the section is erroneous. 


As a standard 'theme' this would be easy, but how can i achieve this with DMS?





Share this post

Link to post
Share on other sites

Use an 'action' to insert your PHP into every page.

Share this post

Link to post
Share on other sites


Well, as you didn't include any info as to where you want the code, i'll proceed to make one up...


I want to add a div before the postloop on every page... http://screencast.com/t/8Id7FTmYZdUm Using actionmap i find the action i want...


add_action( 'pagelines_before_postloop', 'add_my_loop_div' );

function add_my_loop_div() {

    echo '<div id="glenny">Hello World!</div>';



what if i only want it on post ID 234?


add_action( 'pagelines_before_postloop', 'add_my_loop_div_234' );
function add_my_loop_div_234() {
    if( ! is_page( 234 ) )
        return false;
    echo '<div id="glenny">Hello World!</div>';

Share this post

Link to post
Share on other sites

ok apologies I should have been more specific. Here is the php I actually want to output:-


<?php if( $images ): ?>
        <ul class="cb-slideshow">
            <?php foreach( $images as $image ): ?>
<li style="background-image:url('<?php echo $image['url']; ?>');"></li>

            <?php endforeach; ?>

<?php endif; ?>

I presume there is no way to write directly to a single.php or equivalent file?

Share this post

Link to post
Share on other sites

no, you need to use an action or filter.


What is $imges? Where is that variable being set?

Share this post

Link to post
Share on other sites

That is a very good question :D  as its something I've had issues with. $imges is set by the act plugin under:-




... about half way down the page.


Hopefully you are going to tell me how to gather the field or ignore it if it isn't present... as my tests aren't outputting it even though the field is being served on the page

Share this post

Link to post
Share on other sites

  • Similar Content

    • KathleenAspenns
      By KathleenAspenns+
      I would like to upgrade my site to PHP 7, but there is an error warning in the PL Framework theme. I should think this should be fixed asap, I cannot be the only person trying to be up to date.
      1976 | ERROR | preg_replace() - /e modifier is deprecated since PHP 5.5 and removed since PHP 7.0
    • Dan Haddock
      By Dan Haddock
      DMS: Latest Version
      Running a Child Theme
      Wordpress: 4.8.3
      Akismet Anti-Spam 
      Coming Soon Page & Maintenance Mode by SeedProd
      Contact Form 7
      Cookie Law Info
      DMS Professional Tools    
      Enhanced Media Library
      Google Analytics for WordPress by MonsterInsights
      Google XML Sitemap    
      Jetpack by WordPress.com
      MailChimp for WordPress
      PageLines Updater
      Really Simple SSL
      Schema App Structured Data
      Sucuri Security - Auditing, Malware Scanner and Hardening  
      Uber reCaptcha
      Yoast SEO
      Problem Below
      Hi Team,
      I am looking to style the Continue Reading Button with the PHP you provided in an earlier ticket here: 
      I put the PHP code into my site, however I do not get my Icon back, I just get back Read More >>
      I have attached a screenshot of the code in place on my site along with the output.
      Interested to know what I may be doing wrong? - I am very new to PHP so a bit apprehensive on this.
      The Images: https://drive.google.com/open?id=0B0i4JJXa2jdQN2xoakZNRUdmaU0
      Let me know if you need any more information from me.
    • Jared Smith
      By Jared Smith+
      I haven't figured out how to get the "Sync Loaded Item" option in templates menu of Platform 5 to stay checked. It doesn't give me an option to save settings when I select it, and when I select it then click off the editor, it unselects. Also if I select it before loading a template, it doesn't stay checked there either.  Whats going on?
    • Queue-it
      By Queue-it+
      I created a Pagelines template for a "Post type" post. Whenever creating a new post page it firstly display that template post and I have to manually change it in the scope from "All of type posts " to "Current page". 
      Is there a way to fix that? 

    • richardjacruz
      By richardjacruz+
      I'm building a website in a dev environment at
      I want to import a bunch of products, and then have the products have a different template than the default template. 
      I also want to change the default template for blog posts.
      Before I go making changes, can I do this where the post type of "products" has its own global template, and the same with blog posts?
      For instance, in a product I might want to have a widget for categories, similar products, etc., and in the blog I may want list of the latest posts, blog categories, link to an email sign-up landing page, etc.