We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8345
    • 147 Posts
    I have found many threads about integrating Wordpress content into MODx but how to fo opposite?

    For example I need to have a footer links at /blog (Wordpress) change aswell when they are changed at root directory main website (MODx). I guess I have to create page with (blank) template and include the code of the footer there but how to include it at Wordpress?

    Thanks’s in advance.
    • You could use a plugin using OnDocFormSave (or OnChunkFormSave, if you want to use a chunk instead of a document), get the ID of the document (or chunk), and if it’s your footer, save it to wherever Wordpress saves its footer content.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10449
        • 956 Posts
          • 8345
          • 147 Posts
          You could use a plugin using OnDocFormSave
          OK, I understand that it’s possible then let MODx to write the document content into Wordpress footer.php file under /blog/wp-content/themes/theme_name/footer.php? What plugin uses that or how that can be done?

          Created from MODx document that uses blank template with some content (alias: footer.php and I don’t have defined at configuration any prefix or suffix) and wrote to Wordpress template:
          <?php include( TEMPLATEPATH . '/../../../../footer.php' ); ?>

          Didn’t work. But if I deleted that document from MODx and just uploaded footer.php to root then it works but if I create same file from MODx then doesn’t.

          Thanks for help.
            • 10449
            • 956 Posts
            The link I posted above shows nicely how to include a document from outside WP.

            So, e.g. if you created a document with your footer content in MODx, and this document has id 55, you would simply use

            in your WP-template.

            This will only work if you have allow_url_fopen or/and allow_url_include in your PHP-settings = true.
            Maybe you need to change that behaviour in your php.ini file or .htaccess (depends on server configuration)

              • 8345
              • 147 Posts
              Thanks a lot for your help but unfortunatelly


              didn’t work for me. PHP info said allow_url_fopen = On & allow_url_include = Off. As I have this site in shared hosting, I can’t change php.ini file but can of course edit .htaccess.

              I have also installed URL normalization (canonicalization) plugin so http://lawyerpronto.com/index.php?id=139 changes automatically to http://lawyerpronto.com/139 so I tried to include it like that, too but also didn’t work. Should I change .htaccess somehow?


              • There's a better way to do this, if your WP and MODX installs are on the same server, so I thought it might be useful to post it here.

                Including MODX Revo chunks in Wordpress Templates

                First, add the following code to the functions.php file of your Wordpress theme. Be sure to change "/BASE/PATH/TO/YOUR/MODX/INSTALL/PLEASE/REPLACE/" to your actual MODX base path.

                define('MODX_API_MODE', true);
                require_once '/BASE/PATH/TO/YOUR/MODX/INSTALL/PLEASE/REPLACE/index.php';
                function get_modx_chunk($chunkName, $properties = array(), $resourceId = 0, $context = 'web') {
                    $modx = new modX();
                    /*Initialize the selected context*/
                    $modx->getService('error','error.modError', '', '');
                    /*if resourceId is 0, switch to whatever is the site start*/
                    if($resourceId == 0) {
                        $resourceId = $modx->getOption('site_start', null, 1);
                    /*process the chunk as it would appear on the selected resource*/
                    $resource = $modx->getObject('modResource',$resourceId);
                    $modx->resource = $resource;
                    $modx->resourceIdentifier = $resourceId;
                    $output = $modx->getChunk($chunkName, $properties);
                    /* get the max iterations tags are processed before processing is terminated */
                    $maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);
                    /* parse all cacheable tags first */
                    $modx->getParser()->processElementTags('', $output, false, false, '[[', ']]', array(), $maxIterations);
                    /* parse all non-cacheable and remove unprocessed tags */
                    $modx->getParser()->processElementTags('', $output, true, true, '[[', ']]', array(), $maxIterations);
                    return $output;

                This function gets a chunk from MODX and parses any uncached tags in the chunk.

                Then put code like this where you want a MODX chunk to appear in your Wordpress theme, replacing "my-chunk-name" with your chunk name.


                You can pass an optional array of properties into the chunk using the second argument.

                By default, the chunk will be rendered as it would appear on the site_start resource (i.e. the homepage). If you want it to render as if it were in some other resource, pass the ID of that resource in the third argument.

                By default, the chunk will be rendered in the "web" context. If you want to use another context, pass that as the fourth argument. Example:

                    echo(get_modx_chunk('my-chunk-name', array('my-property' => 'value'), 23, 'my-context'));